![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test application for Freedom KL25Z, mouse driven by accelerometer and click with TSI interface
Dependencies: MMA8451Q TSI USBDevice mbed
Fork of Airmouse by
main.cpp@0:a7df8e8cc00c, 2013-06-24 (annotated)
- Committer:
- Future_FThierry
- Date:
- Mon Jun 24 23:23:47 2013 +0000
- Revision:
- 0:a7df8e8cc00c
- Child:
- 1:2bdcfc75ee32
first pub
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Future_FThierry | 0:a7df8e8cc00c | 1 | #include "mbed.h" |
Future_FThierry | 0:a7df8e8cc00c | 2 | #include "USBMouse.h" |
Future_FThierry | 0:a7df8e8cc00c | 3 | #include "MMA8451Q.h" |
Future_FThierry | 0:a7df8e8cc00c | 4 | #include "TSISensor.h" |
Future_FThierry | 0:a7df8e8cc00c | 5 | |
Future_FThierry | 0:a7df8e8cc00c | 6 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
Future_FThierry | 0:a7df8e8cc00c | 7 | |
Future_FThierry | 0:a7df8e8cc00c | 8 | USBMouse mouse; |
Future_FThierry | 0:a7df8e8cc00c | 9 | Serial pc(USBTX, USBRX); // tx, rx |
Future_FThierry | 0:a7df8e8cc00c | 10 | |
Future_FThierry | 0:a7df8e8cc00c | 11 | int main() |
Future_FThierry | 0:a7df8e8cc00c | 12 | { |
Future_FThierry | 0:a7df8e8cc00c | 13 | float click =0; |
Future_FThierry | 0:a7df8e8cc00c | 14 | int16_t x = 0; |
Future_FThierry | 0:a7df8e8cc00c | 15 | int16_t y = 0; |
Future_FThierry | 0:a7df8e8cc00c | 16 | TSISensor tsi; |
Future_FThierry | 0:a7df8e8cc00c | 17 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
Future_FThierry | 0:a7df8e8cc00c | 18 | |
Future_FThierry | 0:a7df8e8cc00c | 19 | while (1) { |
Future_FThierry | 0:a7df8e8cc00c | 20 | x = -10*acc.getAccY(); |
Future_FThierry | 0:a7df8e8cc00c | 21 | y = 10*acc.getAccX(); |
Future_FThierry | 0:a7df8e8cc00c | 22 | |
Future_FThierry | 0:a7df8e8cc00c | 23 | mouse.move(x, y); |
Future_FThierry | 0:a7df8e8cc00c | 24 | |
Future_FThierry | 0:a7df8e8cc00c | 25 | click=tsi.readPercentage(); |
Future_FThierry | 0:a7df8e8cc00c | 26 | //pc.printf("%f\n",click); |
Future_FThierry | 0:a7df8e8cc00c | 27 | if (click>0.70) |
Future_FThierry | 0:a7df8e8cc00c | 28 | mouse.press(MOUSE_LEFT); |
Future_FThierry | 0:a7df8e8cc00c | 29 | else |
Future_FThierry | 0:a7df8e8cc00c | 30 | mouse.release(MOUSE_LEFT); |
Future_FThierry | 0:a7df8e8cc00c | 31 | |
Future_FThierry | 0:a7df8e8cc00c | 32 | if((click<0.30)&&(click>0)) |
Future_FThierry | 0:a7df8e8cc00c | 33 | |
Future_FThierry | 0:a7df8e8cc00c | 34 | mouse.press(MOUSE_RIGHT); |
Future_FThierry | 0:a7df8e8cc00c | 35 | else |
Future_FThierry | 0:a7df8e8cc00c | 36 | mouse.release(MOUSE_RIGHT); |
Future_FThierry | 0:a7df8e8cc00c | 37 | |
Future_FThierry | 0:a7df8e8cc00c | 38 | wait(0.001); |
Future_FThierry | 0:a7df8e8cc00c | 39 | |
Future_FThierry | 0:a7df8e8cc00c | 40 | } |
Future_FThierry | 0:a7df8e8cc00c | 41 | } |