a simple code with a not-so-simple mbed freeze

Dependencies:   MPU6050 mbed-rtos mbed

Revision:
0:b1322cbc592f
Child:
1:d2011078309d
diff -r 000000000000 -r b1322cbc592f main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 14 20:12:51 2013 +0000
@@ -0,0 +1,73 @@
+#include "mbed.h"
+#include "MPU6050.h"
+
+
+DigitalOut myled(LED1);
+Serial pc(USBTX, USBRX);
+MPU6050 mpu(0x69);
+
+int16_t ax, ay, az;
+int16_t gx, gy, gz;
+int16_t moy[64];
+int comptFin=0;
+int comptDeb=0;
+int moyZ=0;
+
+void moyennage_Z()
+{
+    for (int n=0; n<64; n++) {
+        moyZ=moyZ+moy[n];
+
+
+    }
+    moyZ=moyZ/64;
+}
+
+
+
+
+int main()
+{
+    pc.printf("MPU6050 test\n\n\r");
+    pc.printf("MPU6050 initialize \n\r");
+
+    mpu.initialize();
+    pc.printf("MPU6050 testConnection \n\r");
+
+    bool mpu6050TestResult = mpu.testConnection();
+    if(mpu6050TestResult) {
+        pc.printf("MPU6050 test passed \n\r");
+
+        while(comptFin<64) {
+            mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
+            moy[comptFin]=az;
+            comptFin++;
+
+        }
+        moyennage_Z();
+        while(1) {
+            mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
+            moy[comptFin]=az;
+            comptFin++;
+            comptFin%=64;
+            moyZ-=moy[comptDeb]/64;            
+            comptDeb++;
+            comptDeb%=64;
+            moyZ+=moy[comptFin]/64;
+          //  moyennage_Z();
+            printf("%i\n\r",moyZ+17000);
+            wait(.001);
+
+
+
+
+
+        }
+
+
+    } else {
+        pc.printf("MPU6050 test failed \n\r");
+    }
+
+    
+}