[vc_row][vc_column width=”1/1″][vc_column_text]
[/vc_column_text][vc_text_separator title=”Code” title_align=”separator_align_center”][vc_column_text]
/*
@Name: Esplora Joystick Mouse
@Author: TONYLABS
@Website: <a href="http://www.tonylabs.com">http://www.tonylabs.com</a>
@Shop: <a href="http://tonylabs.taobao.com">http://tonylabs.taobao.com</a>
This sample reads the X, Y value of the joystick, and controls the position of the mouse. By doing this, Arduino Esplora changes into a mouser.
Note: when you do this, your real mouse will not be able to control your PC. If you want to restore, please do the following:
1) Unplug Esplora
2) Open sample code of EsploraBlink
3)Press the reset button on Esplora, and at the same time plug in the USB cable of Esplora
4) Click the upload button
5) When the code finished download, we can release the reset button
*/
#include <Esplora.h>
void setup()
{
Serial.begin(9600);
Mouse.begin(); //Get control of mouse
}
void loop()
{
int xValue = Esplora.readJoystickX();
int yValue = Esplora.readJoystickY();
int button = Esplora.readJoystickSwitch();
Serial.print("Joystick X: ");
Serial.print(xValue);
Serial.print("\tY: ");
Serial.print(yValue);
Serial.print("\tButton: ");
Serial.print(button);
int mouseX = map( xValue,-512, 512, 10, -10);
int mouseY = map( yValue,-512, 512, -10, 10);
Mouse.move(mouseX, mouseY, 0);
delay(10);
}
/*
@Name: Esplora Joystick Mouse
@Translation: TONYLABS
@Website: <a href="http://www.tonylabs.com">http://www.tonylabs.com</a>
@Shop: <a href="http://tonylabs.taobao.com">http://tonylabs.taobao.com</a>
*/
[/vc_column_text][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.