a simple code with a not-so-simple mbed freeze
Dependencies: MPU6050 mbed-rtos mbed
Diff: main.cpp
- Revision:
- 1:d2011078309d
- Parent:
- 0:b1322cbc592f
- Child:
- 2:141571165c57
--- a/main.cpp Thu Feb 14 20:12:51 2013 +0000 +++ b/main.cpp Mon Feb 18 11:02:59 2013 +0000 @@ -1,17 +1,14 @@ #include "mbed.h" #include "MPU6050.h" - +#include "rtos.h" DigitalOut myled(LED1); -Serial pc(USBTX, USBRX); +Serial pc1(USBTX, USBRX); MPU6050 mpu(0x69); -int16_t ax, ay, az; -int16_t gx, gy, gz; +int moyZ=0; int16_t moy[64]; -int comptFin=0; -int comptDeb=0; -int moyZ=0; + void moyennage_Z() { @@ -20,23 +17,40 @@ } - moyZ=moyZ/64; + moyZ=(int)moyZ/64; } +void mon_thr(void const *args) +{ + while (true) { + myled=!myled; + } +} int main() + { - pc.printf("MPU6050 test\n\n\r"); - pc.printf("MPU6050 initialize \n\r"); + + Thread thread(mon_thr); + pc1.printf("MPU6050 test\n\n\r"); + pc1.printf("MPU6050 initialize \n\r"); mpu.initialize(); - pc.printf("MPU6050 testConnection \n\r"); + pc1.printf("MPU6050 testConnection \n\r"); + + int16_t ax, ay, az; + int16_t gx, gy, gz; + + +int comptFin=0; +int comptDeb=0; + bool mpu6050TestResult = mpu.testConnection(); if(mpu6050TestResult) { - pc.printf("MPU6050 test passed \n\r"); + pc1.printf("MPU6050 test passed \n\r"); while(comptFin<64) { mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); @@ -46,18 +60,22 @@ } moyennage_Z(); while(1) { - mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); - moy[comptFin]=az; - comptFin++; + while(comptFin<64) { + mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); + moy[comptFin]=az; + comptFin++; + wait(0.01); + } + + comptFin%=64; - moyZ-=moy[comptDeb]/64; + moyZ-=(int)moy[comptDeb]/64; comptDeb++; comptDeb%=64; - moyZ+=moy[comptFin]/64; - // moyennage_Z(); + moyZ+=(int)moy[comptFin]/64; + //moyennage_Z(); printf("%i\n\r",moyZ+17000); - wait(.001); - + wait(0.01); @@ -66,8 +84,8 @@ } else { - pc.printf("MPU6050 test failed \n\r"); + pc1.printf("MPU6050 test failed \n\r"); } - + }