Mrunal Mirani / Mbed 2 deprecated Exp4

Dependencies:   MMA8451Q mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MMA8451Q.h"
00003 
00004 
00005   PinName const SDA = PTE25;
00006   PinName const SCL = PTE24;
00007 
00008 #define MMA8451_I2C_ADDRESS (0x1d<<1)
00009 Ticker acctick;
00010 DigitalOut fallled(LED2);
00011 void acctick_isr(void);
00012 void acctick_isr(void)
00013 {
00014     float x, y, z,a;
00015         x = acc.getAccX();
00016         y = acc.getAccY();
00017         z = acc.getAccZ();
00018         a=sqrt(pow(x,2)+pow(y,2)+pow(z,2));
00019         wait(0.1f);
00020         printf("X: %1.2f, Y: %1.2f, Z: %1.2f, a: %1.2f \n", x, y, z,a);
00021 }
00022 int main(void)
00023 {
00024     MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
00025     fallled=1;
00026     acctick.attach(&acctick_isr,0.01);
00027     printf("MMA8451 ID: %d\n", acc.getWhoAmI());
00028 
00029     while (true);
00030 }