This is a mouse which uses the integrated accelerometer
Dependencies: MMA8451Q USBDevice mbed
Fork of FRDM_MMA8451Q by
Diff: main.cpp
- Revision:
- 8:c156421f0523
- Parent:
- 5:bf5becf7469c
diff -r 70775be9f474 -r c156421f0523 main.cpp --- a/main.cpp Tue Feb 19 23:46:45 2013 +0000 +++ b/main.cpp Wed Sep 24 22:33:41 2014 +0000 @@ -1,18 +1,67 @@ #include "mbed.h" +#include "USBMouse.h" #include "MMA8451Q.h" #define MMA8451_I2C_ADDRESS (0x1d<<1) +MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); +USBMouse mouse; +DigitalIn b1(PTC7); +Timer timer; + int main(void) { - MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); - PwmOut rled(LED_RED); - PwmOut gled(LED_GREEN); - PwmOut bled(LED_BLUE); + + int16_t x = 0; + int16_t y = 0; + uint8_t button=0; + int cswitch=0; while (true) { - rled = 1.0 - abs(acc.getAccX()); - gled = 1.0 - abs(acc.getAccY()); - bled = 1.0 - abs(acc.getAccZ()); - wait(0.1); + + x=-(acc.getAccX()*10); + y=acc.getAccY()*10; + + if(b1==1) + { + button=1; + mouse.click(button); + wait(.05); + } + else + {button=0;} + + + if((cswitch==1)&&(x==0)&&(y==0)) + { + timer.start(); + while((cswitch==1)&&(timer.read()<=2)) + { + x=-(acc.getAccX()*10); + y=acc.getAccY()*10; + if((x!=0)||(y!=0)) + { + cswitch=0; + timer.stop(); + } + } + if(timer.read()>=2) + { + mouse.click(1); + wait(.05); + mouse.click(1); + timer.stop(); + timer.reset(); + cswitch=0; + } + } + + if((x!=0)||(y!=0)) + {cswitch=1;} + + x=-(acc.getAccX()*10); + y=acc.getAccY()*10; + mouse.move(x, y); + + wait(0.005); } }