test

Dependencies:   mbed MMA8452Q

Fork of HelloWorld by Simon Ford

Revision:
15:b4b2e73faefb
Parent:
13:64137db317ab
Child:
16:0b58c14b639d
--- a/main.cpp	Thu Aug 31 15:27:13 2017 +0000
+++ b/main.cpp	Thu Aug 31 15:47:06 2017 +0000
@@ -9,26 +9,38 @@
 
 int main() {
     
-     float x, y, z ;
+     //float x, y, z ;
  
-     MMA8452Q acc(p9,p10,0x1d);
+     MMA8452Q acc(p9,p10,0x1d);     // acceleration object
  
      while (true) {       
-         x = acc.getAccX() ;
-         y = acc.getAccY() ;
-         z = acc.getAccZ() ;
+        // x = acc.getAccX() ;
+        // y = acc.getAccY() ;
+        // z = acc.getAccZ() ;
         // printf("X[%.2f] Y[%.2f] Z[%.2f]\n",x, y, z) ;
          wait(0.1);
 
+        float z = 0.707;
         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 degree = resultat * 18000.0/314.0;
-         pc.printf("valeur deg = %f", degree);
-         degree = degree * 10;
-         int degreInt = (int)degree;
-         pc.printf("valeur deg = %d", degreInt);
+        pc.printf("valeur rad = %f", resultat);
+        float degree = resultat * 18000.0/314.0;
+        pc.printf("valeur deg = %f", degree);
+        degree = degree * 10;
+        int degreInt = (int)degree;
+        pc.printf("valeur deg = %d", degreInt);
+         
          
-         //degreInt
+         // extracting digits
+        char digits[4];
+        int i = 0;
+        while(degreInt > 0) {
+        digits[i]= degreInt % 10;    //to get the right most digit
+        pc.printf("digit %c = %c", i, digits[i]);
+        degreInt /= 10;              //reduce the number by one digit
+        ++i;
+        }
+        //digits[i]='\0'    //terminate the string
+         
          
          
          /*