aboutsummaryrefslogtreecommitdiff
path: root/libraries/Esplora/Beginners/EsploraJoystickMouse
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-01-06 18:38:03 +0100
committerCristian Maglie <c.maglie@bug.st>2013-01-06 18:38:03 +0100
commitc01bc2b62f76a5d417e5ed13dcb0c047a4f67224 (patch)
tree4703fc452282756f3c40d38f9d41b1a28e0bf0f6 /libraries/Esplora/Beginners/EsploraJoystickMouse
parent5f4e55a3d274838388696c3f8130b0f2dc40daf7 (diff)
Merged upcoming 1.0.4 and updated revision log
Diffstat (limited to 'libraries/Esplora/Beginners/EsploraJoystickMouse')
-rw-r--r--libraries/Esplora/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino50
1 files changed, 50 insertions, 0 deletions
diff --git a/libraries/Esplora/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino b/libraries/Esplora/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino
new file mode 100644
index 0000000..8d9260e
--- /dev/null
+++ b/libraries/Esplora/Beginners/EsploraJoystickMouse/EsploraJoystickMouse.ino
@@ -0,0 +1,50 @@
+/*
+ Esplora Joystick Mouse
+
+ This sketch shows you how to read the joystick and use it to control the movement
+ of the cursor on your computer. You're making your Esplora into a mouse!
+
+ WARNING: this sketch will take over your mouse movement. If you lose control
+ of your mouse do the following:
+ 1) unplug the Esplora.
+ 2) open the EsploraBlink sketch
+ 3) hold the reset button down while plugging your Esplora back in
+ 4) while holding reset, click "Upload"
+ 5) when you see the message "Done compiling", release the reset button.
+
+ This will stop your Esplora from controlling your mouse while you upload a sketch
+ that doesn't take control of the mouse.
+
+ Created on 22 Dec 2012
+ by Tom Igoe
+
+ This example is in the public domain.
+ */
+
+#include <Esplora.h>
+
+void setup()
+{
+ Serial.begin(9600); // initialize serial communication with your computer
+ Mouse.begin(); // take control of the mouse
+}
+
+void loop()
+{
+ int xValue = Esplora.readJoystickX(); // read the joystick's X position
+ int yValue = Esplora.readJoystickY(); // read the joystick's Y position
+ int button = Esplora.readJoystickSwitch(); // read the joystick pushbutton
+ Serial.print("Joystick X: "); // print a label for the X value
+ Serial.print(xValue); // print the X value
+ Serial.print("\tY: "); // print a tab character and a label for the Y value
+ Serial.print(yValue); // print the Y value
+ Serial.print("\tButton: "); // print a tab character and a label for the button
+ Serial.print(button); // print the button value
+
+ int mouseX = map( xValue,-512, 512, 10, -10); // map the X value to a range of movement for the mouse X
+ int mouseY = map( yValue,-512, 512, -10, 10); // map the Y value to a range of movement for the mouse Y
+ Mouse.move(mouseX, mouseY, 0); // move the mouse
+
+ delay(10); // a short delay before moving again
+}
+