ACCELEROMETRO Y LCD
Dependencies: MMA8451Q mbed TextLCD
Fork of FRDM_MMA8451Q by
main.cpp@9:ad98499b2dc5, 2014-07-19 (annotated)
- Committer:
- mderrant
- Date:
- Sat Jul 19 02:56:47 2014 +0000
- Revision:
- 9:ad98499b2dc5
- Parent:
- 8:d797bfa9f76e
- Child:
- 11:fa2577154dfd
ACELEROMETRO Y LCD
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" |
mderrant | 9:ad98499b2dc5 | 3 | #include "TextLCD.h" |
mderrant | 9:ad98499b2dc5 | 4 | |
mderrant | 9:ad98499b2dc5 | 5 | TextLCD lcd(PTA13, PTD2, PTA4, PTA5, PTC8, PTC9, TextLCD::LCD16x2); // PARA PLACA KL46F |
mderrant | 9:ad98499b2dc5 | 6 | |
mderrant | 9:ad98499b2dc5 | 7 | |
chris | 2:41db78380a6e | 8 | |
sam_grove | 8:d797bfa9f76e | 9 | #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z) |
sam_grove | 8:d797bfa9f76e | 10 | PinName const SDA = PTE25; |
sam_grove | 8:d797bfa9f76e | 11 | PinName const SCL = PTE24; |
sam_grove | 8:d797bfa9f76e | 12 | #elif defined (TARGET_KL05Z) |
sam_grove | 8:d797bfa9f76e | 13 | PinName const SDA = PTB4; |
sam_grove | 8:d797bfa9f76e | 14 | PinName const SCL = PTB3; |
sam_grove | 8:d797bfa9f76e | 15 | #else |
sam_grove | 8:d797bfa9f76e | 16 | #error TARGET NOT DEFINED |
sam_grove | 8:d797bfa9f76e | 17 | #endif |
sam_grove | 8:d797bfa9f76e | 18 | |
chris | 2:41db78380a6e | 19 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
chris | 2:41db78380a6e | 20 | |
mderrant | 9:ad98499b2dc5 | 21 | |
mderrant | 9:ad98499b2dc5 | 22 | int cur; |
chris | 4:367de1084ea9 | 23 | int main(void) { |
mderrant | 9:ad98499b2dc5 | 24 | MMA8451Q acelerometro(SDA, SCL, MMA8451_I2C_ADDRESS); |
sam_grove | 8:d797bfa9f76e | 25 | PwmOut rled(LED1); |
sam_grove | 8:d797bfa9f76e | 26 | PwmOut gled(LED2); |
sam_grove | 8:d797bfa9f76e | 27 | PwmOut bled(LED3); |
sam_grove | 8:d797bfa9f76e | 28 | |
mderrant | 9:ad98499b2dc5 | 29 | // printf("MMA8451 ID: %d\n", acelerometro.getWhoAmI()); |
chris | 4:367de1084ea9 | 30 | |
emilmont | 5:bf5becf7469c | 31 | while (true) { |
sam_grove | 8:d797bfa9f76e | 32 | float x, y, z; |
mderrant | 9:ad98499b2dc5 | 33 | x = rled = 1.0 - abs(acelerometro.getAccX()); |
mderrant | 9:ad98499b2dc5 | 34 | y = gled = 1.0 - abs(acelerometro.getAccY()); |
mderrant | 9:ad98499b2dc5 | 35 | z = bled = 1.0 - abs(acelerometro.getAccZ()); |
chris | 3:f2d3e041d8f2 | 36 | wait(0.1); |
mderrant | 9:ad98499b2dc5 | 37 | // printf("X: %1.4f, Y: %1.4f, Z: %1.4f \n\r", x, y, z); |
mderrant | 9:ad98499b2dc5 | 38 | |
mderrant | 9:ad98499b2dc5 | 39 | lcd.clear(); |
mderrant | 9:ad98499b2dc5 | 40 | lcd.setCursor(cur,0); |
mderrant | 9:ad98499b2dc5 | 41 | lcd.printf(" X Y Z" ); |
mderrant | 9:ad98499b2dc5 | 42 | lcd.setCursor(0,1); |
mderrant | 9:ad98499b2dc5 | 43 | lcd.printf("%1.2f, %1.2f, %1.2f", x, y, z); |
mderrant | 9:ad98499b2dc5 | 44 | |
mderrant | 9:ad98499b2dc5 | 45 | |
mderrant | 9:ad98499b2dc5 | 46 | |
mderrant | 9:ad98499b2dc5 | 47 | |
chris | 2:41db78380a6e | 48 | } |
chris | 2:41db78380a6e | 49 | } |