Bluetooth
Dependencies: MMA8451Q USBDevice mbed
main.cpp@0:5bba5d416948, 2014-09-23 (annotated)
- Committer:
- gerardo_carmona
- Date:
- Tue Sep 23 20:59:26 2014 +0000
- Revision:
- 0:5bba5d416948
Bluetooth
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gerardo_carmona | 0:5bba5d416948 | 1 | #include "mbed.h" |
gerardo_carmona | 0:5bba5d416948 | 2 | #include "MMA8451Q.h" |
gerardo_carmona | 0:5bba5d416948 | 3 | #include "USBMouse.h" |
gerardo_carmona | 0:5bba5d416948 | 4 | |
gerardo_carmona | 0:5bba5d416948 | 5 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
gerardo_carmona | 0:5bba5d416948 | 6 | PinName const SDA = PTE25; |
gerardo_carmona | 0:5bba5d416948 | 7 | PinName const SCL = PTE24; |
gerardo_carmona | 0:5bba5d416948 | 8 | #elif defined (TARGET_KL05Z) |
gerardo_carmona | 0:5bba5d416948 | 9 | PinName const SDA = PTB4; |
gerardo_carmona | 0:5bba5d416948 | 10 | PinName const SCL = PTB3; |
gerardo_carmona | 0:5bba5d416948 | 11 | #elif defined (TARGET_K20D50M) |
gerardo_carmona | 0:5bba5d416948 | 12 | PinName const SDA = PTB1; |
gerardo_carmona | 0:5bba5d416948 | 13 | PinName const SCL = PTB0; |
gerardo_carmona | 0:5bba5d416948 | 14 | #else |
gerardo_carmona | 0:5bba5d416948 | 15 | #error TARGET NOT DEFINED |
gerardo_carmona | 0:5bba5d416948 | 16 | #endif |
gerardo_carmona | 0:5bba5d416948 | 17 | |
gerardo_carmona | 0:5bba5d416948 | 18 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
gerardo_carmona | 0:5bba5d416948 | 19 | |
gerardo_carmona | 0:5bba5d416948 | 20 | int main(void) |
gerardo_carmona | 0:5bba5d416948 | 21 | { |
gerardo_carmona | 0:5bba5d416948 | 22 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
gerardo_carmona | 0:5bba5d416948 | 23 | USBMouse mouse; |
gerardo_carmona | 0:5bba5d416948 | 24 | DigitalIn boton(PTA1); |
gerardo_carmona | 0:5bba5d416948 | 25 | |
gerardo_carmona | 0:5bba5d416948 | 26 | printf("MMA8451 ID: %d\n", acc.getWhoAmI()); |
gerardo_carmona | 0:5bba5d416948 | 27 | |
gerardo_carmona | 0:5bba5d416948 | 28 | while (true) { |
gerardo_carmona | 0:5bba5d416948 | 29 | float x, y; |
gerardo_carmona | 0:5bba5d416948 | 30 | int value; |
gerardo_carmona | 0:5bba5d416948 | 31 | |
gerardo_carmona | 0:5bba5d416948 | 32 | x = acc.getAccX() * 10; |
gerardo_carmona | 0:5bba5d416948 | 33 | y = acc.getAccY() * 10; |
gerardo_carmona | 0:5bba5d416948 | 34 | |
gerardo_carmona | 0:5bba5d416948 | 35 | value = boton; |
gerardo_carmona | 0:5bba5d416948 | 36 | if (value == 1){ |
gerardo_carmona | 0:5bba5d416948 | 37 | mouse.click(MOUSE_LEFT); |
gerardo_carmona | 0:5bba5d416948 | 38 | wait(0.5); |
gerardo_carmona | 0:5bba5d416948 | 39 | } |
gerardo_carmona | 0:5bba5d416948 | 40 | |
gerardo_carmona | 0:5bba5d416948 | 41 | mouse.move((int)x, (int)y); |
gerardo_carmona | 0:5bba5d416948 | 42 | |
gerardo_carmona | 0:5bba5d416948 | 43 | wait(0.001f); |
gerardo_carmona | 0:5bba5d416948 | 44 | |
gerardo_carmona | 0:5bba5d416948 | 45 | } |
gerardo_carmona | 0:5bba5d416948 | 46 | } |