Lab 3ES_ John Curran T00214119

Dependencies:   mbed MMA7660

Revision:
4:efd9328bb9f0
Parent:
3:7380a26ac26f
Child:
5:72d55b40feef
diff -r 7380a26ac26f -r efd9328bb9f0 main.cpp
--- a/main.cpp	Sat Apr 17 15:48:16 2021 +0000
+++ b/main.cpp	Sat Apr 17 17:35:23 2021 +0000
@@ -1,20 +1,36 @@
-//Uses the measured z-acceleration to drive leds 2 and 3 of the mbed
 
 #include "mbed.h"
 #include "MMA7660.h"
+#include <stdio.h>
+#include <math.h>
+#define PI 3.14159265
 Serial pc(USBTX,USBRX);// serial communications
 MMA7660 MMA(p28, p27);
 
 DigitalOut connectionLed(LED1);
-PwmOut Zaxis_p(LED2);
-PwmOut Zaxis_n(LED3);
+
+float calculateAngle(float x, float y, float z, float val, float ret){
+    float angle =0;
+  
+  val = 180.0 / PI;
+
+   ret  = atan (x) * val;
+   ret  = atan (y) * val;
+   ret  = atan (z) * val;
+   printf("The arc tangent of %lf. %lf, %lf is %lf degrees \n\r ", x, y, z, ret);
+  
+    
+    return angle;    
+}
 
 int main() {  
     if (MMA.testConnection())
         connectionLed = 1;
         
     while(1) {
-        pc.printf ("%f, %f, %f \r\n", MMA.x(), MMA.y(), MMA.z() );
+        float val;
+        float ret;
+        pc.printf ("%f, \r\n", calculateAngle (MMA.x(), MMA.y(), MMA.z(),val,ret ));
         wait (0.5);
     }