Zdenka Šibíková / Mbed 2 deprecated FRDM_MMA8451Quhol

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 #if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
00005   PinName const SDA = PTE25;
00006   PinName const SCL = PTE24;
00007 #elif defined (TARGET_KL05Z)
00008   PinName const SDA = PTB4;
00009   PinName const SCL = PTB3;
00010 #elif defined (TARGET_K20D50M)
00011   PinName const SDA = PTB1;
00012   PinName const SCL = PTB0;
00013 #else
00014   #error TARGET NOT DEFINED
00015 #endif
00016 
00017 #define MMA8451_I2C_ADDRESS (0x1d<<1)
00018 Serial pc(USBTX,USBRX);
00019 int main(void)
00020 {
00021     MMA8451Q acc(SDA, SCL, MMA8451_I2C_ADDRESS);
00022     
00023 
00024     printf("MMA8451 ID: %d\n", acc.getWhoAmI());
00025 
00026     while (true) {
00027         float x, y, z;
00028         x = abs(acc.getAccX());
00029         y = abs(acc.getAccY());
00030         z = abs(acc.getAccZ());
00031         
00032         pc.printf("X: %1.2f, Y: %1.2f, Z: %1.2f\n\r", 180*asin(x/sqrt(x*x+z*z+y*y))/3.14159, 180*asin(y/sqrt(x*x+z*z+y*y))/3.14159, 180*asin(z/sqrt(x*x+z*z+y*y))/3.14159);
00033     }
00034 }