Prints Pitch & Slope Angles

Dependencies:   mbed MMA7660

Committer:
t00203814
Date:
Wed Aug 07 01:11:25 2019 +0000
Revision:
0:885c71e3dd67
T00203814

Who changed what in which revision?

UserRevisionLine numberNew contents of line
t00203814 0:885c71e3dd67 1 #include "mbed.h"//includes mbed header
t00203814 0:885c71e3dd67 2 #include "MMA7660.h"//includes MMA7660 header
t00203814 0:885c71e3dd67 3
t00203814 0:885c71e3dd67 4 #define PI 3.14159265// defines PI as 3.14159265
t00203814 0:885c71e3dd67 5
t00203814 0:885c71e3dd67 6 Serial pc(USBTX, USBRX);// sets up serial connection to PC
t00203814 0:885c71e3dd67 7 MMA7660 MMA(p28, p27);// declares MMA7660 on P27 & p28 and calles them MMA
t00203814 0:885c71e3dd67 8
t00203814 0:885c71e3dd67 9
t00203814 0:885c71e3dd67 10 float calculateAngle(float x, float y, float z) {// sets up a float values called calculateAngler, x, y & z
t00203814 0:885c71e3dd67 11 float angle = 0;// iniates a float value called angle and sets it to zero
t00203814 0:885c71e3dd67 12 angle = (atan(x/sqrt((y*y)+(z*z)))*180/PI);//Calculating the pitch from formular in instructions
t00203814 0:885c71e3dd67 13 pc.printf("Pitch angle is %.3f degrees\n\n\r",angle);
t00203814 0:885c71e3dd67 14 angle = (atan(y/sqrt((x*x)+(z*z)))*180/PI);//Calculating the roll from formular in instructions
t00203814 0:885c71e3dd67 15 pc.printf("Roll angle is %.3f degrees\n\n\r",angle);
t00203814 0:885c71e3dd67 16 wait(3);// waits 3 seconds
t00203814 0:885c71e3dd67 17 return angle;
t00203814 0:885c71e3dd67 18 }
t00203814 0:885c71e3dd67 19
t00203814 0:885c71e3dd67 20
t00203814 0:885c71e3dd67 21
t00203814 0:885c71e3dd67 22 int main() {
t00203814 0:885c71e3dd67 23
t00203814 0:885c71e3dd67 24 while(1) {
t00203814 0:885c71e3dd67 25 pc.printf(" X %f Y %f Z %f angle %.2f degrees \n", MMA.x(), MMA.y(), MMA.z(), calculateAngle(MMA.x(), MMA.y(), MMA.z()));// prints to Pc
t00203814 0:885c71e3dd67 26 wait(1);// waits 1 second
t00203814 0:885c71e3dd67 27
t00203814 0:885c71e3dd67 28 }
t00203814 0:885c71e3dd67 29 }
t00203814 0:885c71e3dd67 30