Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- This is a bit of code for the Esplora.
- It turns your Esplora into a mouse the you use sort of like a Wii remote
- */
- #include <Esplora.h>
- void setup()
- {
- Serial.begin(9600);
- Mouse.begin();
- }
- void loop()
- {
- int clickLeft = Esplora.readButton(2);
- int clickRight = Esplora.readButton(1);
- int zAxis = Esplora.readAccelerometer(Z_AXIS); // read the accelerometer's Z axis
- int yAxis = Esplora.readAccelerometer(Y_AXIS); // read the accelerometer's Y axis
- if(Esplora.readSlider() != 0){ //Fail safe just in case
- int mouseX = map( zAxis,-250, 250, -30, 30); // map zAxis to a range of movement for the mouse X
- int mouseY = map( yAxis,-250, 250, -30, 30); // map yAxis to a range of movement for the mouse Y
- Mouse.move(mouseX, mouseY, 0); // move the mouse
- if(clickLeft == LOW) // click the mouse's left button if switch 2 is pressed
- {
- Mouse.press(); // left click by default
- delay(10);
- }
- else{
- Mouse.release();
- }
- if(clickRight == LOW) // click the mouse's right button switch 1 is pressed
- {
- Mouse.press(MOUSE_RIGHT);
- delay(10);
- }
- else{
- Mouse.release(MOUSE_RIGHT);
- }
- delay(10); // a short delay before moving again
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment