I2C通信を使用した角速度測定、LCD表示サンプル
Dependencies: mbed mbed_mpu6050_i2c_raw_register AQM0802
Revision 6:c940ad83d2c5, committed 2019-07-22
- Comitter:
- yusaku0125
- Date:
- Mon Jul 22 09:43:17 2019 +0000
- Parent:
- 5:8c482bdfb9e8
- Commit message:
- test
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Jul 19 19:09:08 2019 +0000
+++ b/main.cpp Mon Jul 22 09:43:17 2019 +0000
@@ -11,20 +11,28 @@
double gx,gy,gz; //Z角速度情報を格納
int i_gz; //Z軸データint型変換格納
char str[5]; //LCD表示用文字列
+
+
pc.baud(9600); //通信速度は9600bps
mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec);//[1000deg/sec]を測定上限とする。
lcd.init(); //LCD初期化
lcd.locate(1,0); //桁、行
lcd.print("GYRO_Z");//1行目に「GYRO_Z」を表示
- while(true) {
+
+ while(true) {
+ wait(0.2);
+ //★☆角速度情報の取得☆★
mpu.readGyroscope(gx, gy, gz);//関数仕様上3軸すべて角速度取得する。
i_gz=(int)gz; //doubleは大きすぎるのでint型へ変換
+
+ //★☆ターミナルへの角速度表示☆★
pc.printf("gz:%d\r\n", i_gz);//Z軸方向のみ表示する。(他は使わない)
+
+ //★☆LCDへの角速度表示☆★
lcd.locate(1,1);//桁、行
lcd.print(" ");//表示クリア
sprintf(str,"%4d",i_gz);
lcd.locate(1,1);//桁、行
lcd.print(str); //表示クリア
- wait(0.2);
}
}