MMS8452Q test program

Dependencies:   MMA8452Q mbed

main.cpp

Committer:
Rhyme
Date:
2015-12-13
Revision:
0:333671d10f11
Child:
1:3607d35e1740

File content as of revision 0:333671d10f11:

#include "mbed.h"
#include "MMA8452Q.h"

#if defined (TARGET_KL25Z)
#define PIN_SCL  PTE1
#define PIN_SDA  PTE0
#elif defined (TARGET_KL46Z)
#define PIN_SCL  PTE1
#define PIN_SDA  PTE0
#elif defined (TARGET_K64F)
#define PIN_SCL  PTE24
#define PIN_SDA  PTE25
#elif defined (TARGET_K22F)
#define PIN_SCL  PTE1
#define PIN_SDA  PTE0
#elif defined (TARGET_KL05Z)
#define PIN_SCL  PTB3
#define PIN_SDA  PTB4
#elif defined (TARGET_NUCLEO_F411RE)
#define PIN_SCL  PB_8
#define PIN_SDA  PB_9
#else
 #error TARGET NOT DEFINED
#endif
 
#define MMA8452_I2C_ADDRESS (0x1d)
 
int main(void) {
     float x, y, z ;

     MMA8452Q acc(PIN_SDA, PIN_SCL, MMA8452_I2C_ADDRESS);
 
     while (true) {       
         x = acc.getAccX() ;
         y = acc.getAccY() ;
         z = acc.getAccZ() ;
         printf("X[%.2f] Y[%.2f] Z[%.2f]\n",x, y, z) ;
         wait(0.1);
    }
}