1
1
/*
2
2
Esplora Joystick Mouse
3
-
3
+
4
4
This sketch shows you how to read the joystick and use it to control the movement
5
5
of the cursor on your computer. You're making your Esplora into a mouse!
6
-
6
+
7
7
WARNING: this sketch will take over your mouse movement. If you lose control
8
8
of your mouse do the following:
9
9
1) unplug the Esplora.
10
10
2) open the EsploraBlink sketch
11
11
3) hold the reset button down while plugging your Esplora back in
12
12
4) while holding reset, click "Upload"
13
13
5) when you see the message "Done compiling", release the reset button.
14
-
14
+
15
15
This will stop your Esplora from controlling your mouse while you upload a sketch
16
16
that doesn't take control of the mouse.
17
-
17
+
18
18
Created on 22 Dec 2012
19
19
by Tom Igoe
20
+ Updated 8 March 2014
21
+ by Scott Fitzgerald
20
22
23
+ http://arduino.cc/en/Reference/EsploraReadJoystickSwitch
24
+
21
25
This example is in the public domain.
22
26
*/
23
27
@@ -27,7 +31,7 @@ void setup()
27
31
{
28
32
Serial.begin (9600 ); // initialize serial communication with your computer
29
33
Mouse.begin (); // take control of the mouse
30
- }
34
+ }
31
35
32
36
void loop ()
33
37
{
@@ -41,10 +45,16 @@ void loop()
41
45
Serial.print (" \t Button: " ); // print a tab character and a label for the button
42
46
Serial.print (button); // print the button value
43
47
44
- int mouseX = map ( xValue,-512 , 512 , 10 , -10 ); // map the X value to a range of movement for the mouse X
45
- int mouseY = map ( yValue,-512 , 512 , -10 , 10 ); // map the Y value to a range of movement for the mouse Y
48
+ int mouseX = map (xValue, -512 , 512 , 10 , -10 ); // map the X value to a range of movement for the mouse X
49
+ int mouseY = map (yValue, -512 , 512 , -10 , 10 ); // map the Y value to a range of movement for the mouse Y
46
50
Mouse.move (mouseX, mouseY, 0 ); // move the mouse
47
-
51
+
52
+ if (button == 0 ) { // if the joystick button is pressed
53
+ Mouse.press (); // send a mouse click
54
+ } else {
55
+ Mouse.release (); // if it's not pressed, release the mouse button
56
+ }
57
+
48
58
delay (10 ); // a short delay before moving again
49
59
}
50
60
0 commit comments