![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
I2C通信を使用した角速度測定、LCD表示サンプル
Dependencies: mbed mbed_mpu6050_i2c_raw_register AQM0802
Diff: main.cpp
- Revision:
- 2:f2db52a742b0
- Parent:
- 1:6f743fe9a027
- Child:
- 3:ebd656a9c89f
--- a/main.cpp Thu Dec 13 03:00:27 2018 +0000 +++ b/main.cpp Thu Dec 13 03:07:35 2018 +0000 @@ -8,6 +8,14 @@ DigitalOut led4(LED4); MPU6050 mpu(p9, p10); +void allTurnOffLed() +{ + led1 = 0; + led2 = 0; + led3 = 0; + led4 = 0; +} + void readData() { double ax, ay, az; @@ -15,15 +23,22 @@ double gx, gy, gz; mpu.readGyroscope(gx, gy, gz); pc.printf("%.4lf %.4lf %.4lf %.4lf %.4lf %.4lf\r\n", ax, ay, az, gx, gy, gz); + allTurnOffLed(); + if(ax > ay && ax > az) { + led1 = 1; + } else if(ay > ax && ay > az) { + led2 = 1; + } else if(az > ax && az > ay) { + led3 = 1; + } else { + led4 = 1; + } } int main() { mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec); while(1) { - led1 = 1; readData(); wait(0.2); - led1 = 0; - wait(0.2); } }