![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
a simple code with a not-so-simple mbed freeze
Dependencies: MPU6050 mbed-rtos mbed
main.cpp@0:b1322cbc592f, 2013-02-14 (annotated)
- Committer:
- pommzorz
- Date:
- Thu Feb 14 20:12:51 2013 +0000
- Revision:
- 0:b1322cbc592f
- Child:
- 1:d2011078309d
temps ech constant
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pommzorz | 0:b1322cbc592f | 1 | #include "mbed.h" |
pommzorz | 0:b1322cbc592f | 2 | #include "MPU6050.h" |
pommzorz | 0:b1322cbc592f | 3 | |
pommzorz | 0:b1322cbc592f | 4 | |
pommzorz | 0:b1322cbc592f | 5 | DigitalOut myled(LED1); |
pommzorz | 0:b1322cbc592f | 6 | Serial pc(USBTX, USBRX); |
pommzorz | 0:b1322cbc592f | 7 | MPU6050 mpu(0x69); |
pommzorz | 0:b1322cbc592f | 8 | |
pommzorz | 0:b1322cbc592f | 9 | int16_t ax, ay, az; |
pommzorz | 0:b1322cbc592f | 10 | int16_t gx, gy, gz; |
pommzorz | 0:b1322cbc592f | 11 | int16_t moy[64]; |
pommzorz | 0:b1322cbc592f | 12 | int comptFin=0; |
pommzorz | 0:b1322cbc592f | 13 | int comptDeb=0; |
pommzorz | 0:b1322cbc592f | 14 | int moyZ=0; |
pommzorz | 0:b1322cbc592f | 15 | |
pommzorz | 0:b1322cbc592f | 16 | void moyennage_Z() |
pommzorz | 0:b1322cbc592f | 17 | { |
pommzorz | 0:b1322cbc592f | 18 | for (int n=0; n<64; n++) { |
pommzorz | 0:b1322cbc592f | 19 | moyZ=moyZ+moy[n]; |
pommzorz | 0:b1322cbc592f | 20 | |
pommzorz | 0:b1322cbc592f | 21 | |
pommzorz | 0:b1322cbc592f | 22 | } |
pommzorz | 0:b1322cbc592f | 23 | moyZ=moyZ/64; |
pommzorz | 0:b1322cbc592f | 24 | } |
pommzorz | 0:b1322cbc592f | 25 | |
pommzorz | 0:b1322cbc592f | 26 | |
pommzorz | 0:b1322cbc592f | 27 | |
pommzorz | 0:b1322cbc592f | 28 | |
pommzorz | 0:b1322cbc592f | 29 | int main() |
pommzorz | 0:b1322cbc592f | 30 | { |
pommzorz | 0:b1322cbc592f | 31 | pc.printf("MPU6050 test\n\n\r"); |
pommzorz | 0:b1322cbc592f | 32 | pc.printf("MPU6050 initialize \n\r"); |
pommzorz | 0:b1322cbc592f | 33 | |
pommzorz | 0:b1322cbc592f | 34 | mpu.initialize(); |
pommzorz | 0:b1322cbc592f | 35 | pc.printf("MPU6050 testConnection \n\r"); |
pommzorz | 0:b1322cbc592f | 36 | |
pommzorz | 0:b1322cbc592f | 37 | bool mpu6050TestResult = mpu.testConnection(); |
pommzorz | 0:b1322cbc592f | 38 | if(mpu6050TestResult) { |
pommzorz | 0:b1322cbc592f | 39 | pc.printf("MPU6050 test passed \n\r"); |
pommzorz | 0:b1322cbc592f | 40 | |
pommzorz | 0:b1322cbc592f | 41 | while(comptFin<64) { |
pommzorz | 0:b1322cbc592f | 42 | mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); |
pommzorz | 0:b1322cbc592f | 43 | moy[comptFin]=az; |
pommzorz | 0:b1322cbc592f | 44 | comptFin++; |
pommzorz | 0:b1322cbc592f | 45 | |
pommzorz | 0:b1322cbc592f | 46 | } |
pommzorz | 0:b1322cbc592f | 47 | moyennage_Z(); |
pommzorz | 0:b1322cbc592f | 48 | while(1) { |
pommzorz | 0:b1322cbc592f | 49 | mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); |
pommzorz | 0:b1322cbc592f | 50 | moy[comptFin]=az; |
pommzorz | 0:b1322cbc592f | 51 | comptFin++; |
pommzorz | 0:b1322cbc592f | 52 | comptFin%=64; |
pommzorz | 0:b1322cbc592f | 53 | moyZ-=moy[comptDeb]/64; |
pommzorz | 0:b1322cbc592f | 54 | comptDeb++; |
pommzorz | 0:b1322cbc592f | 55 | comptDeb%=64; |
pommzorz | 0:b1322cbc592f | 56 | moyZ+=moy[comptFin]/64; |
pommzorz | 0:b1322cbc592f | 57 | // moyennage_Z(); |
pommzorz | 0:b1322cbc592f | 58 | printf("%i\n\r",moyZ+17000); |
pommzorz | 0:b1322cbc592f | 59 | wait(.001); |
pommzorz | 0:b1322cbc592f | 60 | |
pommzorz | 0:b1322cbc592f | 61 | |
pommzorz | 0:b1322cbc592f | 62 | |
pommzorz | 0:b1322cbc592f | 63 | |
pommzorz | 0:b1322cbc592f | 64 | |
pommzorz | 0:b1322cbc592f | 65 | } |
pommzorz | 0:b1322cbc592f | 66 | |
pommzorz | 0:b1322cbc592f | 67 | |
pommzorz | 0:b1322cbc592f | 68 | } else { |
pommzorz | 0:b1322cbc592f | 69 | pc.printf("MPU6050 test failed \n\r"); |
pommzorz | 0:b1322cbc592f | 70 | } |
pommzorz | 0:b1322cbc592f | 71 | |
pommzorz | 0:b1322cbc592f | 72 | |
pommzorz | 0:b1322cbc592f | 73 | } |