Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of FRDM_MMA8451Q by
main.cpp@10:7b19730eab23, 2014-12-11 (annotated)
- Committer:
- gchaves
- Date:
- Thu Dec 11 22:48:04 2014 +0000
- Revision:
- 10:7b19730eab23
- Parent:
- 9:d4bffe27a7bf
- Child:
- 11:6d0bc42699fb
accelerometro unicamente andando
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 | 9:d4bffe27a7bf | 10 | #elif defined (TARGET_K20D50M) |
sam_grove | 9:d4bffe27a7bf | 11 | PinName const SDA = PTB1; |
sam_grove | 9:d4bffe27a7bf | 12 | PinName const SCL = PTB0; |
sam_grove | 8:d797bfa9f76e | 13 | #else |
sam_grove | 8:d797bfa9f76e | 14 | #error TARGET NOT DEFINED |
sam_grove | 8:d797bfa9f76e | 15 | #endif |
sam_grove | 8:d797bfa9f76e | 16 | |
chris | 2:41db78380a6e | 17 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
chris | 2:41db78380a6e | 18 | |
sam_grove | 9:d4bffe27a7bf | 19 | int main(void) |
sam_grove | 9:d4bffe27a7bf | 20 | { |
sam_grove | 8:d797bfa9f76e | 21 | MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS); |
sam_grove | 8:d797bfa9f76e | 22 | PwmOut rled(LED1); |
sam_grove | 8:d797bfa9f76e | 23 | PwmOut gled(LED2); |
sam_grove | 8:d797bfa9f76e | 24 | PwmOut bled(LED3); |
sam_grove | 9:d4bffe27a7bf | 25 | |
sam_grove | 8:d797bfa9f76e | 26 | printf("MMA8451 ID: %d\n", acc.getWhoAmI()); |
chris | 4:367de1084ea9 | 27 | |
emilmont | 5:bf5becf7469c | 28 | while (true) { |
sam_grove | 8:d797bfa9f76e | 29 | float x, y, z; |
gchaves | 10:7b19730eab23 | 30 | x = acc.getAccX(); |
gchaves | 10:7b19730eab23 | 31 | y = acc.getAccY(); |
gchaves | 10:7b19730eab23 | 32 | z = acc.getAccZ(); |
gchaves | 10:7b19730eab23 | 33 | rled = 1.0f - abs(x); |
gchaves | 10:7b19730eab23 | 34 | gled = 1.0f - abs(y); |
gchaves | 10:7b19730eab23 | 35 | bled = 1.0f - abs(z); |
gchaves | 10:7b19730eab23 | 36 | wait_ms(100); |
gchaves | 10:7b19730eab23 | 37 | printf("%1.2f,%1.2f,%1.2f \n", x, y, z);// X , Y, Z |
chris | 2:41db78380a6e | 38 | } |
chris | 2:41db78380a6e | 39 | } |