test

Dependencies:   mbed MMA8452Q

Fork of HelloWorld by Simon Ford

Revision:
17:c463c5a434ec
Parent:
16:0b58c14b639d
Child:
18:171cb8d2f243
diff -r 0b58c14b639d -r c463c5a434ec main.cpp
--- a/main.cpp	Thu Aug 31 16:52:41 2017 +0000
+++ b/main.cpp	Thu Aug 31 17:37:12 2017 +0000
@@ -9,26 +9,36 @@
 
 int main() {
     
-     //float x, y, z ;
+     float x, y, z ;
  
      MMA8452Q acc(p9,p10,0x1d);     // acceleration object
  
-     //while (true) {       
-        // x = acc.getAccX() ;
-        // y = acc.getAccY() ;
-        // z = acc.getAccZ() ;
+     while (true) {       
+         x = acc.getAccX() ;
+         y = acc.getAccY() ;
+         z = acc.getAccZ() ;
         // printf("X[%.2f] Y[%.2f] Z[%.2f]\n",x, y, z) ;
          wait(0.1);
 
-       // float angle = ((2*x*x+2*y*y)/(x*x+y*y+z*z))+1;
-        
-        float resultat = (3.14/2.0) -( z + (z *z * z)/6.0 + (3*z*z*z*z*z)/40.0);
-        pc.printf("valeur rad = %f", resultat);
+        float angle = 1-(((2*x*x+2*y*y)/(x*x+y*y+z*z)));
+        pc.printf("avant acos = %f", angle);
+        //float resultat = ((3.14/2.0) -( angle + (angle *angle * angle)/6.0 + (3*angle*angle*angle*angle*angle)/40.0))/2;
+        float resultat = acos(angle)/2.0;
+        pc.printf("valeur rad new= %f", resultat);
         float degree = resultat * 18000.0/314.0;
-        pc.printf("valeur deg = %f", degree);
+        pc.printf("valeur deg new = %f", degree);
         degree = degree * 10;
         int degreInt = (int)degree;
-        pc.printf("valeur deg = %d", degreInt);
+        pc.printf("valeur deg new = %d", degreInt);
+        
+        
+        float resultat2 = (3.14/2.0) -( z + (z *z * z)/6.0 + (3*z*z*z*z*z)/40.0);
+        pc.printf("valeur rad old = %f", resultat2);
+        float degree2 = resultat2 * 18000.0/314.0;
+        pc.printf("valeur deg old = %f", degree2);
+        degree2 = degree2 * 10;
+        int degreInt2 = (int)degree;
+        pc.printf("valeur deg old = %d", degreInt2);
          
         int rep;
          // extracting digits
@@ -41,29 +51,33 @@
         degreInt /= 10;              //reduce the number by one digit
         ++i;
         }
-        //digits[i]='\0'    //terminate the string
          
-         
-         
-         
+         cs = 0;
+         accel.write(0x76); // Clear display
+         cs = 1;
+         wait(0.1);
+         cs = 0;
+         accel.write(0x77); // Decimal control command
+         accel.write(0x04);// Turn on decimal
+         cs = 1;
+         wait(0.01);
          cs = 0;
          accel.write(digits[3]);
          cs = 1;
-         wait(2);
+         wait(0.01);
          cs = 0;
          accel.write(digits[2]);
          cs = 1;
-         wait(2);
+         wait(0.01);
          cs = 0;
          accel.write(digits[1]);
          cs = 1;
-         wait(2);
+         wait(0.01);
          cs = 0;
          accel.write(digits[0]);
          cs = 1;
-         wait(2);
-         wait(1); 
-        
+         wait(0.1);
+        }
 }