..
Dependencies: MMA8451Q TSI USBDevice mbed
main.cpp@0:a3f78bcda713, 2017-02-09 (annotated)
- Committer:
- anmolhardik
- Date:
- Thu Feb 09 13:43:14 2017 +0000
- Revision:
- 0:a3f78bcda713
aa
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
anmolhardik | 0:a3f78bcda713 | 1 | #include "mbed.h" |
anmolhardik | 0:a3f78bcda713 | 2 | #include "USBMouse.h" |
anmolhardik | 0:a3f78bcda713 | 3 | #include "MMA8451Q.h" |
anmolhardik | 0:a3f78bcda713 | 4 | #include "TSISensor.h" |
anmolhardik | 0:a3f78bcda713 | 5 | Serial pc (USBTX,USBRX); |
anmolhardik | 0:a3f78bcda713 | 6 | BusOut led (PTB18,PTB19,PTD1); |
anmolhardik | 0:a3f78bcda713 | 7 | int main () |
anmolhardik | 0:a3f78bcda713 | 8 | { |
anmolhardik | 0:a3f78bcda713 | 9 | USBMouse mouse; |
anmolhardik | 0:a3f78bcda713 | 10 | MMA8451Q acc(PTE25,PTE24,0x1d<<1); |
anmolhardik | 0:a3f78bcda713 | 11 | TSISensor tsi; |
anmolhardik | 0:a3f78bcda713 | 12 | float x,y, tsi_value; |
anmolhardik | 0:a3f78bcda713 | 13 | while(1) |
anmolhardik | 0:a3f78bcda713 | 14 | { |
anmolhardik | 0:a3f78bcda713 | 15 | x=-(acc.getAccY()*6); |
anmolhardik | 0:a3f78bcda713 | 16 | y=acc.getAccX()*6; |
anmolhardik | 0:a3f78bcda713 | 17 | mouse.move(x,y); |
anmolhardik | 0:a3f78bcda713 | 18 | |
anmolhardik | 0:a3f78bcda713 | 19 | tsi_value = tsi.readPercentage(); |
anmolhardik | 0:a3f78bcda713 | 20 | if(tsi_value>0.0&&tsi_value<=0.4) |
anmolhardik | 0:a3f78bcda713 | 21 | { |
anmolhardik | 0:a3f78bcda713 | 22 | pc.printf("tsi value = %f\n\r",tsi_value); |
anmolhardik | 0:a3f78bcda713 | 23 | |
anmolhardik | 0:a3f78bcda713 | 24 | mouse.press(MOUSE_LEFT); |
anmolhardik | 0:a3f78bcda713 | 25 | |
anmolhardik | 0:a3f78bcda713 | 26 | |
anmolhardik | 0:a3f78bcda713 | 27 | |
anmolhardik | 0:a3f78bcda713 | 28 | led=0x6; |
anmolhardik | 0:a3f78bcda713 | 29 | } |
anmolhardik | 0:a3f78bcda713 | 30 | else if(tsi_value>=0.6&&tsi_value<=1.0) |
anmolhardik | 0:a3f78bcda713 | 31 | { |
anmolhardik | 0:a3f78bcda713 | 32 | pc.printf("tsi value= %f\n\r",tsi_value); |
anmolhardik | 0:a3f78bcda713 | 33 | |
anmolhardik | 0:a3f78bcda713 | 34 | mouse.press(MOUSE_RIGHT); |
anmolhardik | 0:a3f78bcda713 | 35 | |
anmolhardik | 0:a3f78bcda713 | 36 | |
anmolhardik | 0:a3f78bcda713 | 37 | led=0x3; |
anmolhardik | 0:a3f78bcda713 | 38 | } |
anmolhardik | 0:a3f78bcda713 | 39 | else |
anmolhardik | 0:a3f78bcda713 | 40 | { |
anmolhardik | 0:a3f78bcda713 | 41 | |
anmolhardik | 0:a3f78bcda713 | 42 | mouse.release(MOUSE_LEFT); |
anmolhardik | 0:a3f78bcda713 | 43 | mouse.release(MOUSE_RIGHT); |
anmolhardik | 0:a3f78bcda713 | 44 | } |
anmolhardik | 0:a3f78bcda713 | 45 | |
anmolhardik | 0:a3f78bcda713 | 46 | } |
anmolhardik | 0:a3f78bcda713 | 47 | } |
anmolhardik | 0:a3f78bcda713 | 48 | |
anmolhardik | 0:a3f78bcda713 | 49 |