Skip to content

Commit 9810e89

Browse files
committed
Update to Esplora example
Added Mouse.press to Esplora Joystick Mouse example
1 parent 16915f1 commit 9810e89

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
11
/*
22
Esplora Joystick Mouse
3-
3+
44
This sketch shows you how to read the joystick and use it to control the movement
55
of the cursor on your computer. You're making your Esplora into a mouse!
6-
6+
77
WARNING: this sketch will take over your mouse movement. If you lose control
88
of your mouse do the following:
99
1) unplug the Esplora.
1010
2) open the EsploraBlink sketch
1111
3) hold the reset button down while plugging your Esplora back in
1212
4) while holding reset, click "Upload"
1313
5) when you see the message "Done compiling", release the reset button.
14-
14+
1515
This will stop your Esplora from controlling your mouse while you upload a sketch
1616
that doesn't take control of the mouse.
17-
17+
1818
Created on 22 Dec 2012
1919
by Tom Igoe
20+
Updated 8 March 2014
21+
by Scott Fitzgerald
2022
23+
http://arduino.cc/en/Reference/EsploraReadJoystickSwitch
24+
2125
This example is in the public domain.
2226
*/
2327

@@ -27,7 +31,7 @@ void setup()
2731
{
2832
Serial.begin(9600); // initialize serial communication with your computer
2933
Mouse.begin(); // take control of the mouse
30-
}
34+
}
3135

3236
void loop()
3337
{
@@ -41,10 +45,16 @@ void loop()
4145
Serial.print("\tButton: "); // print a tab character and a label for the button
4246
Serial.print(button); // print the button value
4347

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
4650
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+
4858
delay(10); // a short delay before moving again
4959
}
5060

0 commit comments

Comments
 (0)