Prints Pitch & Slope Angles

Dependencies:   mbed MMA7660

Revision:
0:885c71e3dd67
diff -r 000000000000 -r 885c71e3dd67 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Aug 07 01:11:25 2019 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"//includes mbed header
+#include "MMA7660.h"//includes MMA7660 header
+ 
+#define PI 3.14159265// defines PI as 3.14159265
+
+Serial pc(USBTX, USBRX);// sets up serial connection to PC
+MMA7660 MMA(p28, p27);// declares MMA7660 on P27 & p28 and calles them MMA
+ 
+ 
+float calculateAngle(float x, float y, float z) {// sets up a float values called calculateAngler, x, y & z
+float angle = 0;// iniates a float value called angle and sets it to zero
+    angle = (atan(x/sqrt((y*y)+(z*z)))*180/PI);//Calculating the pitch from formular in instructions
+    pc.printf("Pitch angle is %.3f degrees\n\n\r",angle);
+    angle = (atan(y/sqrt((x*x)+(z*z)))*180/PI);//Calculating the roll from formular in instructions
+    pc.printf("Roll angle is %.3f degrees\n\n\r",angle);
+    wait(3);// waits 3 seconds
+    return angle;
+}
+ 
+  
+ 
+int main() {  
+ 
+    while(1) {
+        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
+          wait(1);// waits 1 second
+ 
+}   
+    }
+