prueba comunicación i^2c

Dependencies:   mbed

Committer:
fonz626
Date:
Sat May 16 21:37:52 2015 +0000
Revision:
0:b52c6d67b596
prueba comunicaci?n 1^2c

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fonz626 0:b52c6d67b596 1 #include "mbed.h"
fonz626 0:b52c6d67b596 2 #include "MMA8451Q.h"
fonz626 0:b52c6d67b596 3
fonz626 0:b52c6d67b596 4 PinName const SDA = PTE25;
fonz626 0:b52c6d67b596 5 PinName const SCL = PTE24;
fonz626 0:b52c6d67b596 6 DigitalOut myled(LED2);
fonz626 0:b52c6d67b596 7
fonz626 0:b52c6d67b596 8 #define MMA8451_I2C_ADDRESS (0x1d<<1)
fonz626 0:b52c6d67b596 9
fonz626 0:b52c6d67b596 10
fonz626 0:b52c6d67b596 11 int main(){
fonz626 0:b52c6d67b596 12
fonz626 0:b52c6d67b596 13 MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
fonz626 0:b52c6d67b596 14
fonz626 0:b52c6d67b596 15 while (true) {
fonz626 0:b52c6d67b596 16 float x, y, z;
fonz626 0:b52c6d67b596 17 x = abs(acc.getAccX());
fonz626 0:b52c6d67b596 18 y = abs(acc.getAccY());
fonz626 0:b52c6d67b596 19 z = abs(acc.getAccZ());
fonz626 0:b52c6d67b596 20
fonz626 0:b52c6d67b596 21 if (x>0.5)
fonz626 0:b52c6d67b596 22 {
fonz626 0:b52c6d67b596 23 myled = 0;
fonz626 0:b52c6d67b596 24 }
fonz626 0:b52c6d67b596 25 else
fonz626 0:b52c6d67b596 26 {
fonz626 0:b52c6d67b596 27 myled = 1;
fonz626 0:b52c6d67b596 28 }
fonz626 0:b52c6d67b596 29 printf("%f",x);
fonz626 0:b52c6d67b596 30 }
fonz626 0:b52c6d67b596 31
fonz626 0:b52c6d67b596 32 }