I2C通信を使用した角速度測定、LCD表示サンプル

Dependencies:   mbed mbed_mpu6050_i2c_raw_register AQM0802

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "AQM0802.h"
00003 #include "mpu6050.h"
00004 
00005 Serial pc(USBTX, USBRX);
00006 MPU6050 mpu(D4, D5);
00007 AQM0802 lcd(D4,D5);
00008 
00009 int main()
00010 {
00011     double gx,gy,gz;    //Z角速度情報を格納
00012     int i_gz;           //Z軸データint型変換格納
00013     char str[5];        //LCD表示用文字列
00014     
00015     
00016     pc.baud(9600);      //通信速度は9600bps
00017     mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec);//[1000deg/sec]を測定上限とする。
00018     lcd.init();         //LCD初期化
00019     lcd.locate(1,0);    //桁、行
00020     lcd.print("GYRO_Z");//1行目に「GYRO_Z」を表示
00021     
00022     while(true) {     
00023         wait(0.2);
00024         //★☆角速度情報の取得☆★
00025         mpu.readGyroscope(gx, gy, gz);//関数仕様上3軸すべて角速度取得する。
00026         i_gz=(int)gz;   //doubleは大きすぎるのでint型へ変換
00027         
00028         //★☆ターミナルへの角速度表示☆★
00029         pc.printf("gz:%d\r\n", i_gz);//Z軸方向のみ表示する。(他は使わない)
00030         
00031         //★☆LCDへの角速度表示☆★        
00032         lcd.locate(1,1);//桁、行
00033         lcd.print("     ");//表示クリア
00034         sprintf(str,"%4d",i_gz);
00035         lcd.locate(1,1);//桁、行
00036         lcd.print(str); //表示クリア
00037     }
00038 }