Mouse using the Touch sensor interface
Dependencies: mbed TSI MMA8451Q USBDevice
Diff: main.cpp
- Revision:
- 0:7d12552d9912
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Jan 23 16:56:25 2021 +0000 @@ -0,0 +1,38 @@ +#include "mbed.h" +#include "MMA8451Q.h" +#define MMA8451_I2C_ADDRESS (0x1D<<1) +#include "TSISensor.h" +#include "USBMouse.h" +MMA8451Q acc(PTE25,PTE24,MMA8451_I2C_ADDRESS); +TSISensor tsi; +USBMouse mouse; +int main() +{ + float x=0; + float y=0; + int s=10; + float tsival; + while(1) + { + x=acc.getAccX(); + y=acc.getAccY(); + tsival = tsi.readPercentage(); + x=x*s; + y=y*s; + mouse.move(-y,x); + if((tsival>0.05&&tsival<0.33)) + { + mouse.press(MOUSE_LEFT); + } + else if((tsival>0.66&&tsival<1)) + { + mouse.press(MOUSE_RIGHT); + + } + else + { + mouse.release(MOUSE_LEFT); + mouse.release(MOUSE_RIGHT); + } + } +}