ジャイロセンサを使用してLCDディスプレイに角速度情報を表示するプログラム
Dependencies: mbed
Dependents: line_trace_sample line_trace_sample_saitou line_trace_sample_tamada line_trace_ver2
Revision 4:8522af820314, committed 2019-07-29
- Comitter:
- GGU
- Date:
- Mon Jul 29 02:31:42 2019 +0000
- Parent:
- 3:ebd656a9c89f
- Commit message:
- test
Changed in this revision
main.cpp | Show diff for this revision Revisions of this file |
diff -r ebd656a9c89f -r 8522af820314 main.cpp --- a/main.cpp Thu Dec 13 15:35:41 2018 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -#include "mbed.h" -#include "mpu6050.h" - -Serial pc(USBTX, USBRX); -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); -MPU6050 mpu(p9, p10); - -void turnOffAllLed() -{ - led1 = 0; - led2 = 0; - led3 = 0; - led4 = 0; -} - -void readData() -{ - double ax, ay, az; - mpu.readAccelemeter(ax, ay, az); - 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); - turnOffAllLed(); - 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() { - pc.baud(115200); - mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec); - while(true) { - readData(); - wait(0.2); - } -}