NONE
Dependencies: MMA8451Q USBDevice mbed
Fork of USBMouse_HelloWorld by
main.cpp@5:15f41f12f4eb, 2017-07-07 (annotated)
- Committer:
- naray23
- Date:
- Fri Jul 07 01:07:38 2017 +0000
- Revision:
- 5:15f41f12f4eb
- Parent:
- 3:b8caa902d79e
NONE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 2:e7b766501add | 1 | #include "mbed.h" |
samux | 2:e7b766501add | 2 | #include "USBMouse.h" |
naray23 | 5:15f41f12f4eb | 3 | #include "MMA8451Q.h" |
naray23 | 5:15f41f12f4eb | 4 | |
naray23 | 5:15f41f12f4eb | 5 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
naray23 | 5:15f41f12f4eb | 6 | PinName const SDA = PTE25; |
naray23 | 5:15f41f12f4eb | 7 | PinName const SCL = PTE24; |
naray23 | 5:15f41f12f4eb | 8 | #elif defined (TARGET_KL05Z) |
naray23 | 5:15f41f12f4eb | 9 | PinName const SDA = PTB4; |
naray23 | 5:15f41f12f4eb | 10 | PinName const SCL = PTB3; |
naray23 | 5:15f41f12f4eb | 11 | #elif defined (TARGET_K20D50M) |
naray23 | 5:15f41f12f4eb | 12 | PinName const SDA = PTB1; |
naray23 | 5:15f41f12f4eb | 13 | PinName const SCL = PTB0; |
naray23 | 5:15f41f12f4eb | 14 | #else |
naray23 | 5:15f41f12f4eb | 15 | #error TARGET NOT DEFINED |
naray23 | 5:15f41f12f4eb | 16 | #endif |
naray23 | 5:15f41f12f4eb | 17 | |
naray23 | 5:15f41f12f4eb | 18 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
samux | 2:e7b766501add | 19 | |
samux | 2:e7b766501add | 20 | USBMouse mouse; |
samux | 2:e7b766501add | 21 | |
samux | 2:e7b766501add | 22 | int main() { |
naray23 | 5:15f41f12f4eb | 23 | int x, y,z; |
naray23 | 5:15f41f12f4eb | 24 | |
naray23 | 5:15f41f12f4eb | 25 | |
naray23 | 5:15f41f12f4eb | 26 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
samux | 2:e7b766501add | 27 | while (1) { |
naray23 | 5:15f41f12f4eb | 28 | |
naray23 | 5:15f41f12f4eb | 29 | x =1.0f- abs(10*acc.getAccX()); |
naray23 | 5:15f41f12f4eb | 30 | y = 1.0f- abs(10*acc.getAccY()); |
naray23 | 5:15f41f12f4eb | 31 | z = 1.0f-abs(10*acc.getAccZ()); |
samux | 3:b8caa902d79e | 32 | |
samux | 2:e7b766501add | 33 | mouse.move(x, y); |
samux | 2:e7b766501add | 34 | wait(0.001); |
samux | 2:e7b766501add | 35 | } |
samux | 0:48fd0c31cef5 | 36 | } |