mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Update to Esplora example
Added Mouse.press to Esplora Joystick Mouse example
This commit is contained in:
parent
16915f12a3
commit
9810e896d1
@ -1,9 +1,9 @@
|
||||
/*
|
||||
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.
|
||||
@ -11,13 +11,17 @@
|
||||
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
|
||||
Updated 8 March 2014
|
||||
by Scott Fitzgerald
|
||||
|
||||
http://arduino.cc/en/Reference/EsploraReadJoystickSwitch
|
||||
|
||||
This example is in the public domain.
|
||||
*/
|
||||
|
||||
@ -27,7 +31,7 @@ void setup()
|
||||
{
|
||||
Serial.begin(9600); // initialize serial communication with your computer
|
||||
Mouse.begin(); // take control of the mouse
|
||||
}
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
@ -41,10 +45,16 @@ void loop()
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
if (button == 0) { // if the joystick button is pressed
|
||||
Mouse.press(); // send a mouse click
|
||||
} else {
|
||||
Mouse.release(); // if it's not pressed, release the mouse button
|
||||
}
|
||||
|
||||
delay(10); // a short delay before moving again
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user