ejer 4 pagina embebidos

Dependencies:   mbed MMA8451Q

Committer:
Charin
Date:
Wed Apr 10 14:10:18 2019 +0000
Revision:
0:56cad526113e
sa

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Charin 0:56cad526113e 1 #include "mbed.h"
Charin 0:56cad526113e 2 #include "MMA8451Q.h"
Charin 0:56cad526113e 3
Charin 0:56cad526113e 4 #if defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
Charin 0:56cad526113e 5 PinName const SDA = PTE25;
Charin 0:56cad526113e 6 PinName const SCL = PTE24;
Charin 0:56cad526113e 7 #elif defined (TARGET_KL05Z)
Charin 0:56cad526113e 8 PinName const SDA = PTB4;
Charin 0:56cad526113e 9 PinName const SCL = PTB3;
Charin 0:56cad526113e 10 #elif defined (TARGET_K20D50M)
Charin 0:56cad526113e 11 PinName const SDA = PTB1;
Charin 0:56cad526113e 12 PinName const SCL = PTB0;
Charin 0:56cad526113e 13 #else
Charin 0:56cad526113e 14 #error TARGET NOT DEFINED
Charin 0:56cad526113e 15 #endif
Charin 0:56cad526113e 16
Charin 0:56cad526113e 17 #define MMA8451_I2C_ADDRESS (0x1d<<1)
Charin 0:56cad526113e 18
Charin 0:56cad526113e 19 Ticker timer;
Charin 0:56cad526113e 20
Charin 0:56cad526113e 21
Charin 0:56cad526113e 22
Charin 0:56cad526113e 23 void posicion ()
Charin 0:56cad526113e 24 {
Charin 0:56cad526113e 25 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
Charin 0:56cad526113e 26 PwmOut rled(LED1);
Charin 0:56cad526113e 27 PwmOut gled(LED2);
Charin 0:56cad526113e 28 PwmOut bled(LED3);
Charin 0:56cad526113e 29 float x, y, z;
Charin 0:56cad526113e 30 x = abs(acc.getAccX());
Charin 0:56cad526113e 31 y = abs(acc.getAccY());
Charin 0:56cad526113e 32 z = abs(acc.getAccZ());
Charin 0:56cad526113e 33 rled = 1.0f - x;
Charin 0:56cad526113e 34 gled = 1.0f - y;
Charin 0:56cad526113e 35 bled = 1.0f - z;
Charin 0:56cad526113e 36 printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n", x, y, z);
Charin 0:56cad526113e 37
Charin 0:56cad526113e 38 }
Charin 0:56cad526113e 39
Charin 0:56cad526113e 40 int main(void)
Charin 0:56cad526113e 41 {
Charin 0:56cad526113e 42
Charin 0:56cad526113e 43 timer.attach (&posicion, 0.5);
Charin 0:56cad526113e 44
Charin 0:56cad526113e 45
Charin 0:56cad526113e 46 while (true) {
Charin 0:56cad526113e 47
Charin 0:56cad526113e 48 }
Charin 0:56cad526113e 49 }