MMA interface with the on board accelerometer ,prints the X,YandZ vaues every second

Dependencies:   mbed MMA7660

Committer:
t00203959
Date:
Wed May 22 10:48:24 2019 +0000
Revision:
0:6305a4a6779c
Digital sensors and Equations in C

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t00203959 0:6305a4a6779c 1 #include "mbed.h"
t00203959 0:6305a4a6779c 2 #include "MMA7660.h"
t00203959 0:6305a4a6779c 3
t00203959 0:6305a4a6779c 4
t00203959 0:6305a4a6779c 5 Serial pc(USBTX, USBRX); //tx rx
t00203959 0:6305a4a6779c 6 MMA7660 MMA(p28, p27);
t00203959 0:6305a4a6779c 7
t00203959 0:6305a4a6779c 8 float calculateAngle (float x, float y, float z)
t00203959 0:6305a4a6779c 9 {
t00203959 0:6305a4a6779c 10 float angle =0;
t00203959 0:6305a4a6779c 11
t00203959 0:6305a4a6779c 12 angle = (atan (x/ sqrt((y*y)+(z*z)))*180/3.17);
t00203959 0:6305a4a6779c 13
t00203959 0:6305a4a6779c 14 return angle;
t00203959 0:6305a4a6779c 15
t00203959 0:6305a4a6779c 16 }
t00203959 0:6305a4a6779c 17
t00203959 0:6305a4a6779c 18 int main ()
t00203959 0:6305a4a6779c 19 {
t00203959 0:6305a4a6779c 20 // if MMA.test connection() ) //
t00203959 0:6305a4a6779c 21
t00203959 0:6305a4a6779c 22 while (1) {
t00203959 0:6305a4a6779c 23 printf("x %f, y %f, z %f ang %f\n\r", MMA.x(), MMA.y(), MMA.z(), calculateAngle(MMA.x(), MMA.y(), MMA.z()));
t00203959 0:6305a4a6779c 24 wait (1);
t00203959 0:6305a4a6779c 25 }
t00203959 0:6305a4a6779c 26 }