![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
I2C通信を使用した角速度測定、LCD表示サンプル
Dependencies: mbed mbed_mpu6050_i2c_raw_register AQM0802
main.cpp
- Committer:
- yusaku0125
- Date:
- 2019-07-19
- Revision:
- 4:bf507fe18cb2
- Parent:
- 3:ebd656a9c89f
- Child:
- 5:8c482bdfb9e8
File content as of revision 4:bf507fe18cb2:
#include "mbed.h" #include "AQM0802.h" #include "mpu6050.h" Serial pc(USBTX, USBRX); MPU6050 mpu(D4, D5); AQM0802 lcd(I2C_SDA,I2C_SCL); int main() { double gx,gy,gz; //Z角速度情報を格納 int i_gz; char str[5]; pc.baud(9600); mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec);//[1000deg/sec]を測定上限とする。 lcd.init(); lcd.locate(1,0);//桁、行 lcd.print("GYRO_Z");//1行目に「GYRO_Z」を表示 while(true) { mpu.readGyroscope(gx, gy, gz);//関数仕様上3軸すべて角速度取得する。 i_gz=(int)gz;//doubleは大きすぎるのでint型へ変換 pc.printf("gz:%d\r\n", i_gz);//Z軸方向のみ表示する。(他は使わない) lcd.locate(1,1);//桁、行 lcd.print(" ");//表示クリア sprintf(str,"%4d",i_gz); lcd.locate(1,1);//桁、行 lcd.print(str);//表示クリア wait(0.2); } }