hvhvh

Dependencies:   MMA8451Q mbed

main.cpp

Committer:
mrunalmirani
Date:
2017-01-18
Revision:
0:3ee8bb19ec63

File content as of revision 0:3ee8bb19ec63:

#include "mbed.h"
#include "MMA8451Q.h"


  PinName const SDA = PTE25;
  PinName const SCL = PTE24;

#define MMA8451_I2C_ADDRESS (0x1d<<1)
Ticker acctick;
DigitalOut fallled(LED2);
void acctick_isr(void);
void acctick_isr(void)
{
    float x, y, z,a;
        x = acc.getAccX();
        y = acc.getAccY();
        z = acc.getAccZ();
        a=sqrt(pow(x,2)+pow(y,2)+pow(z,2));
        wait(0.1f);
        printf("X: %1.2f, Y: %1.2f, Z: %1.2f, a: %1.2f \n", x, y, z,a);
}
int main(void)
{
    MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
    fallled=1;
    acctick.attach(&acctick_isr,0.01);
    printf("MMA8451 ID: %d\n", acc.getWhoAmI());

    while (true);
}