w4spiusbmouse
Dependencies: FXOS8700Q USBDevice mbed
Diff: main.cpp
- Revision:
- 0:5030214d976d
diff -r 000000000000 -r 5030214d976d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 12 15:46:35 2017 +0000 @@ -0,0 +1,43 @@ +#include "mbed.h" +#include "USBMouse.h" +#include "FXOS8700Q.h" + +//I2C lines for FXOS8700Q accelerometer/magnetometer +FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); +DigitalIn leftbutton(SW2); //SW2 will be assigned to the left mouse button +DigitalIn rightbutton(SW3); //SW3 will be assigned to the right mouse button + + +USBMouse mouse; + +int main() +{ + acc.enable(); //enable the accelerometer + float faX, faY, faZ; + int16_t x = 0; + int16_t y = 0; + + while (1) + { + //acc.getAxis(acc_data); + acc.getX(&faX); + acc.getY(&faY); + acc.getZ(&faZ); + x = 10*faX; + y = 10*faY; + + mouse.move(x, y); //move mouse dependant on the postion of the rotation of the mbed + + if(leftbutton==0){ + mouse.press(MOUSE_LEFT); + } + else{mouse.release(MOUSE_LEFT);} + + if(rightbutton==0){ + mouse.press(MOUSE_RIGHT); + } + else{mouse.release(MOUSE_RIGHT);} + + wait(0.001); //updates position every 0.001 seconds + } +} \ No newline at end of file