I2C_comm

Dependencies:   mbed

Fork of I2C_comm by Raphaël Drouin

Files at this revision

API Documentation at this revision

Comitter:
ShaolinPoutine
Date:
Tue Jan 17 15:56:39 2017 +0000
Parent:
2:a83e46376681
Commit message:
k

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jan 16 19:02:49 2017 +0000
+++ b/main.cpp	Tue Jan 17 15:56:39 2017 +0000
@@ -13,6 +13,8 @@
 
 int16_t normal[3] = {0,0,1};
 
+
+
 int printDecimalNumber(int i){
     char chiffres[4];
     if (i > 9999) {
@@ -79,7 +81,9 @@
     int16_t x, y, z;
     int16_t buffer;
     
-    int mean[32];
+    int buffersize = 128;
+    int shiftsize = 7;
+    int mean[buffersize];
     int angle;
     
     int iteration = 0;
@@ -97,22 +101,21 @@
         ((char*) &buffer)[1]= data[4];    //MSB
         z = buffer >> 4;
         
+        z = std::abs(z);
         if (z > 1024)
             z = 1024;
-        if (z < -1024)
-            z = -1024;
         
         int theta = std::acos((double) z / (double) 1024) * radtodeg * 100;
-        mean[iteration % 32] = theta >> 5;
+        mean[iteration % buffersize] = theta >> shiftsize;
         
-        if (iteration % 16 == 0){
+        if (iteration % 64 == 0){
             angle = 0;
-            for (int i = 0; i < 32; i++){
+            for (int i = 0; i < buffersize; i++){
                 angle += mean[i];
             }
             printDecimalNumber(angle);
         }
-        wait(0.006);
+        wait(0.0006);
         iteration++;
     }
 }
\ No newline at end of file