Los 3 mosqueteros-freescale
/
FRDM_MMA8451Q
Prueba acelerometro - ejemplo recuperado
Fork of FRDM_MMA8451Q by
main.cpp@8:d797bfa9f76e, 2014-02-21 (annotated)
- Committer:
- sam_grove
- Date:
- Fri Feb 21 15:33:38 2014 +0000
- Revision:
- 8:d797bfa9f76e
- Parent:
- 5:bf5becf7469c
- Child:
- 9:d4bffe27a7bf
Added support for FRDM-KL05Z, FRDM-KL25Z and FRDM-KL46Z
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 2:41db78380a6e | 1 | #include "mbed.h" |
chris | 2:41db78380a6e | 2 | #include "MMA8451Q.h" |
chris | 2:41db78380a6e | 3 | |
sam_grove | 8:d797bfa9f76e | 4 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
sam_grove | 8:d797bfa9f76e | 5 | PinName const SDA = PTE25; |
sam_grove | 8:d797bfa9f76e | 6 | PinName const SCL = PTE24; |
sam_grove | 8:d797bfa9f76e | 7 | #elif defined (TARGET_KL05Z) |
sam_grove | 8:d797bfa9f76e | 8 | PinName const SDA = PTB4; |
sam_grove | 8:d797bfa9f76e | 9 | PinName const SCL = PTB3; |
sam_grove | 8:d797bfa9f76e | 10 | #else |
sam_grove | 8:d797bfa9f76e | 11 | #error TARGET NOT DEFINED |
sam_grove | 8:d797bfa9f76e | 12 | #endif |
sam_grove | 8:d797bfa9f76e | 13 | |
chris | 2:41db78380a6e | 14 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
chris | 2:41db78380a6e | 15 | |
chris | 4:367de1084ea9 | 16 | int main(void) { |
sam_grove | 8:d797bfa9f76e | 17 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
sam_grove | 8:d797bfa9f76e | 18 | PwmOut rled(LED1); |
sam_grove | 8:d797bfa9f76e | 19 | PwmOut gled(LED2); |
sam_grove | 8:d797bfa9f76e | 20 | PwmOut bled(LED3); |
sam_grove | 8:d797bfa9f76e | 21 | |
sam_grove | 8:d797bfa9f76e | 22 | printf("MMA8451 ID: %d\n", acc.getWhoAmI()); |
chris | 4:367de1084ea9 | 23 | |
emilmont | 5:bf5becf7469c | 24 | while (true) { |
sam_grove | 8:d797bfa9f76e | 25 | float x, y, z; |
sam_grove | 8:d797bfa9f76e | 26 | x = rled = 1.0 - abs(acc.getAccX()); |
sam_grove | 8:d797bfa9f76e | 27 | y = gled = 1.0 - abs(acc.getAccY()); |
sam_grove | 8:d797bfa9f76e | 28 | z = bled = 1.0 - abs(acc.getAccZ()); |
chris | 3:f2d3e041d8f2 | 29 | wait(0.1); |
sam_grove | 8:d797bfa9f76e | 30 | printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z); |
chris | 2:41db78380a6e | 31 | } |
chris | 2:41db78380a6e | 32 | } |