Used the onboard accelerometer (Freescale MMA8451Q) and capacitive sensor APIs of MBED and developed a mouse that alters its sensitivity with respect to the user input. Extended the gesture USB mouse to give it a wireless capability using an nRF24L01P RX-TX pair.
Dependencies: mbed TSI MMA8451Q USBDevice
main.cpp@0:a582e272f873, 2019-01-23 (annotated)
- Committer:
- pratik_sheth_
- Date:
- Wed Jan 23 16:56:28 2019 +0000
- Revision:
- 0:a582e272f873
Used the onboard accelerometer (Freescale MMA8451Q) and capacitive sensor APIs of MBED and developed a mouse that alters its sensitivity with respect to the user input. Extended with wireless capability using nRF module
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pratik_sheth_ | 0:a582e272f873 | 1 | #include "mbed.h" |
pratik_sheth_ | 0:a582e272f873 | 2 | #include "USBMouse.h" |
pratik_sheth_ | 0:a582e272f873 | 3 | #include "MMA8451Q.h" |
pratik_sheth_ | 0:a582e272f873 | 4 | #include "TSISensor.h" |
pratik_sheth_ | 0:a582e272f873 | 5 | |
pratik_sheth_ | 0:a582e272f873 | 6 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
pratik_sheth_ | 0:a582e272f873 | 7 | |
pratik_sheth_ | 0:a582e272f873 | 8 | MMA8451Q acc(PTE25,PTE24, MMA8451_I2C_ADDRESS); |
pratik_sheth_ | 0:a582e272f873 | 9 | TSISensor tsi; |
pratik_sheth_ | 0:a582e272f873 | 10 | USBMouse mouse; |
pratik_sheth_ | 0:a582e272f873 | 11 | |
pratik_sheth_ | 0:a582e272f873 | 12 | int main() |
pratik_sheth_ | 0:a582e272f873 | 13 | { |
pratik_sheth_ | 0:a582e272f873 | 14 | int16_t x = 0; |
pratik_sheth_ | 0:a582e272f873 | 15 | int16_t y = 0; |
pratik_sheth_ | 0:a582e272f873 | 16 | int s=10; |
pratik_sheth_ | 0:a582e272f873 | 17 | |
pratik_sheth_ | 0:a582e272f873 | 18 | while(1) |
pratik_sheth_ | 0:a582e272f873 | 19 | { |
pratik_sheth_ | 0:a582e272f873 | 20 | x= -s*(acc.getAccY()); |
pratik_sheth_ | 0:a582e272f873 | 21 | y= s*acc.getAccX(); |
pratik_sheth_ | 0:a582e272f873 | 22 | |
pratik_sheth_ | 0:a582e272f873 | 23 | mouse.move(x,y); |
pratik_sheth_ | 0:a582e272f873 | 24 | |
pratik_sheth_ | 0:a582e272f873 | 25 | //left click |
pratik_sheth_ | 0:a582e272f873 | 26 | if (tsi.readPercentage() > 0.7) |
pratik_sheth_ | 0:a582e272f873 | 27 | { |
pratik_sheth_ | 0:a582e272f873 | 28 | mouse.press(MOUSE_LEFT); |
pratik_sheth_ | 0:a582e272f873 | 29 | } |
pratik_sheth_ | 0:a582e272f873 | 30 | else |
pratik_sheth_ | 0:a582e272f873 | 31 | { |
pratik_sheth_ | 0:a582e272f873 | 32 | mouse.release(MOUSE_LEFT); |
pratik_sheth_ | 0:a582e272f873 | 33 | } |
pratik_sheth_ | 0:a582e272f873 | 34 | //right click |
pratik_sheth_ | 0:a582e272f873 | 35 | if (tsi.readPercentage() < 0.3 && tsi.readPercentage() > 0) |
pratik_sheth_ | 0:a582e272f873 | 36 | { |
pratik_sheth_ | 0:a582e272f873 | 37 | mouse.press(MOUSE_RIGHT); |
pratik_sheth_ | 0:a582e272f873 | 38 | } |
pratik_sheth_ | 0:a582e272f873 | 39 | else |
pratik_sheth_ | 0:a582e272f873 | 40 | { |
pratik_sheth_ | 0:a582e272f873 | 41 | mouse.release(MOUSE_RIGHT); |
pratik_sheth_ | 0:a582e272f873 | 42 | } |
pratik_sheth_ | 0:a582e272f873 | 43 | } |
pratik_sheth_ | 0:a582e272f873 | 44 | } |