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

Dependencies:   MPU6050 mbed-rtos mbed

main.cpp

Committer:
pommzorz
Date:
2013-02-14
Revision:
0:b1322cbc592f
Child:
1:d2011078309d

File content as of revision 0:b1322cbc592f:

#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");
    }

    
}