Trabajo de materia
Fork of FRDM_MMA8451Q by
main.cpp@11:6d0bc42699fb, 2014-12-17 (annotated)
- Committer:
- gchaves
- Date:
- Wed Dec 17 21:49:12 2014 +0000
- Revision:
- 11:6d0bc42699fb
- Parent:
- 10:7b19730eab23
Trabajando, agregando pedido de datos
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 | 11:6d0bc42699fb | 37 | |
gchaves | 11:6d0bc42699fb | 38 | sscanf |
gchaves | 11:6d0bc42699fb | 39 | printf("##%f//%f//%f//\n", x, y, z);// X , Y, Z |
chris | 2:41db78380a6e | 40 | } |
chris | 2:41db78380a6e | 41 | } |