bubdan

ZY Mouse

Jun 2nd, 2014
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. /*
  2. This is a bit of code for the Esplora.
  3. It turns your Esplora into a mouse the you use sort of like a Wii remote
  4.  */
  5.  
  6. #include <Esplora.h>
  7.  
  8. void setup()
  9. {
  10.   Serial.begin(9600);
  11.   Mouse.begin();
  12. }
  13.  
  14. void loop()
  15. {
  16.  
  17.   int clickLeft = Esplora.readButton(2);
  18.   int clickRight = Esplora.readButton(1);
  19.   int zAxis = Esplora.readAccelerometer(Z_AXIS);        // read the accelerometer's Z axis
  20.   int yAxis = Esplora.readAccelerometer(Y_AXIS);        // read the accelerometer's Y axis
  21.   if(Esplora.readSlider() != 0){ //Fail safe just in case
  22.   int mouseX = map( zAxis,-250, 250, -30, 30);  // map zAxis to a range of movement for the mouse X
  23.   int mouseY = map( yAxis,-250, 250, -30, 30);  // map yAxis to a range of movement for the mouse Y
  24.   Mouse.move(mouseX, mouseY, 0);                 // move the mouse
  25.   if(clickLeft == LOW)  // click the mouse's left button if switch 2 is pressed
  26.   {
  27.     Mouse.press();    // left click by default
  28.     delay(10);
  29.   }
  30.   else{
  31.     Mouse.release();
  32.   }
  33.   if(clickRight == LOW)  // click the mouse's right button switch 1 is pressed
  34.   {
  35.     Mouse.press(MOUSE_RIGHT);
  36.     delay(10);
  37.   }
  38.   else{
  39.     Mouse.release(MOUSE_RIGHT);
  40.   }
  41.   delay(10);                                  // a short delay before moving again
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment