Lab3

Dependencies:   mbed MMA7660

Committer:
GerRoche
Date:
Fri May 24 14:57:02 2019 +0000
Revision:
0:654d905694c3
Lab3

Who changed what in which revision?

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