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@1:12a34d982118, 2016-06-16 (annotated)
- Committer:
- alejo1690
- Date:
- Thu Jun 16 01:07:53 2016 +0000
- Revision:
- 1:12a34d982118
- Parent:
- 0:a7df8e8cc00c
lab
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" |
alejo1690 | 1:12a34d982118 | 3 | #include "USBKeyboard.h" |
Future_FThierry | 0:a7df8e8cc00c | 4 | #include "MMA8451Q.h" |
Future_FThierry | 0:a7df8e8cc00c | 5 | #include "TSISensor.h" |
Future_FThierry | 0:a7df8e8cc00c | 6 | |
Future_FThierry | 0:a7df8e8cc00c | 7 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
Future_FThierry | 0:a7df8e8cc00c | 8 | |
alejo1690 | 1:12a34d982118 | 9 | //USBMouse mouse; |
alejo1690 | 1:12a34d982118 | 10 | USBKeyboard tecla; |
Future_FThierry | 0:a7df8e8cc00c | 11 | Serial pc(USBTX, USBRX); // tx, rx |
Future_FThierry | 0:a7df8e8cc00c | 12 | |
Future_FThierry | 0:a7df8e8cc00c | 13 | int main() |
Future_FThierry | 0:a7df8e8cc00c | 14 | { |
Future_FThierry | 0:a7df8e8cc00c | 15 | float click =0; |
Future_FThierry | 0:a7df8e8cc00c | 16 | int16_t x = 0; |
Future_FThierry | 0:a7df8e8cc00c | 17 | int16_t y = 0; |
Future_FThierry | 0:a7df8e8cc00c | 18 | TSISensor tsi; |
Future_FThierry | 0:a7df8e8cc00c | 19 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
Future_FThierry | 0:a7df8e8cc00c | 20 | |
Future_FThierry | 0:a7df8e8cc00c | 21 | while (1) { |
Future_FThierry | 0:a7df8e8cc00c | 22 | x = -10*acc.getAccY(); |
Future_FThierry | 0:a7df8e8cc00c | 23 | y = 10*acc.getAccX(); |
Future_FThierry | 0:a7df8e8cc00c | 24 | |
alejo1690 | 1:12a34d982118 | 25 | //mouse.move(x, y); |
Future_FThierry | 0:a7df8e8cc00c | 26 | |
Future_FThierry | 0:a7df8e8cc00c | 27 | click=tsi.readPercentage(); |
alejo1690 | 1:12a34d982118 | 28 | //pc.printf("%f\n",y); |
alejo1690 | 1:12a34d982118 | 29 | if (y==10){ |
alejo1690 | 1:12a34d982118 | 30 | if (click>0.69) |
alejo1690 | 1:12a34d982118 | 31 | tecla._putc(97); |
alejo1690 | 1:12a34d982118 | 32 | |
alejo1690 | 1:12a34d982118 | 33 | if((click<0.33)&&(click>0)) |
alejo1690 | 1:12a34d982118 | 34 | tecla._putc(99); |
Future_FThierry | 0:a7df8e8cc00c | 35 | |
alejo1690 | 1:12a34d982118 | 36 | if((click<0.69)&&(click>0.33)) |
alejo1690 | 1:12a34d982118 | 37 | tecla._putc(98); |
alejo1690 | 1:12a34d982118 | 38 | } |
alejo1690 | 1:12a34d982118 | 39 | |
alejo1690 | 1:12a34d982118 | 40 | if (y==0){ |
alejo1690 | 1:12a34d982118 | 41 | if (click>0.69) |
alejo1690 | 1:12a34d982118 | 42 | tecla._putc(100); |
alejo1690 | 1:12a34d982118 | 43 | |
alejo1690 | 1:12a34d982118 | 44 | if((click<0.33)&&(click>0)) |
alejo1690 | 1:12a34d982118 | 45 | tecla._putc(102); |
Future_FThierry | 0:a7df8e8cc00c | 46 | |
alejo1690 | 1:12a34d982118 | 47 | if((click<0.69)&&(click>0.33)) |
alejo1690 | 1:12a34d982118 | 48 | tecla._putc(101); |
alejo1690 | 1:12a34d982118 | 49 | } |
alejo1690 | 1:12a34d982118 | 50 | |
alejo1690 | 1:12a34d982118 | 51 | wait(0.5); |
Future_FThierry | 0:a7df8e8cc00c | 52 | |
Future_FThierry | 0:a7df8e8cc00c | 53 | } |
Future_FThierry | 0:a7df8e8cc00c | 54 | } |