Balancimg MPU6050 by LEDs on PWM
It is possible to observe the MPU6050 data on serial. If serial termimal is not started then still LED application runs.
There are 4 LEDs on LPC1768. So the first 3 LEDs are assign to accelerometer X, Y and Z. The last LED can drive by user. Default it lights a bit. If you want to turn it off then change the value as "190" to "180" on this line: myled4 = cos(190*2.0*3.13/360) * 0.5 + 0.5; If you want to turn it on (full) then change the value as "190" to "0" on above code line.
Diff: main.cpp
- Revision:
- 0:9a1aae56ed19
diff -r 000000000000 -r 9a1aae56ed19 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun Oct 13 12:01:33 2013 +0000 @@ -0,0 +1,45 @@ +#include "mbed.h" +#include "math.h" // to use cos() function for LED4 +#include "MPU6050.h" + +PwmOut myled1(LED1); +PwmOut myled2(LED2); +PwmOut myled3(LED3); +PwmOut myled4(LED4); + +// to see 6050 data on Serial terminal +Serial pc(USBTX, USBRX); +MPU6050 mpu; + +int16_t ax, ay, az; +int16_t gx, gy, gz; + +int main(){ + myled1.period_ms(1); + myled2.period_ms(1); + myled3.period_ms(1); + myled4.period_ms(1); + + pc.printf("MPU6050 test\n\n"); + pc.printf("MPU6050 initialize \n"); + + mpu.initialize(); + pc.printf("MPU6050 testConnection \n"); + + bool mpu6050TestResult = mpu.testConnection(); + if(mpu6050TestResult){ + pc.printf("MPU6050 test passed \n"); + } else{ + pc.printf("MPU6050 test failed \n"); + } + while(1){ + wait(0.2); + mpu.getMotion6(&ax, &ay, &az, &gx, &gy, &gz); + pc.printf("%d\t%d\t%d\t%d\t%d\t%d\n",ax,ay,az,gx,gy,gz); + + myled1 = abs(ax) / 16384.0; + myled2 = abs(ay) / 16384.0; + myled3 = abs(az) / 16384.0; + myled4 = cos(190*2.0*3.13/360) * 0.5 + 0.5; // to see efect of the value which is 0,0076 on LED4 + } +} \ No newline at end of file