Qian Yuyang / Mbed 2 deprecated MPU6050_Demo_V2

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MPU6050.h"
00003 DigitalOut myled(PC_13);
00004 MPU6050 mpu6050(PB_7,PB_6);
00005 Serial pc(PA_2, PA_3,9600);
00006 float yaw,pitch,roll;
00007 int counts;
00008 int main()
00009 { 
00010     pc.printf("Initializing...\n");
00011     while(mpu6050.Init())  //初始化
00012     {
00013         counts+=1;
00014         wait(1);
00015         myled=!myled;
00016         if(counts>10)
00017         {
00018             pc.printf("Initialation failed\n"); // 初始化失败
00019             break;
00020         }   
00021     }
00022     pc.printf("Initialized\n"); //初始化完成
00023     while(1) 
00024     {
00025         mpu6050.receiveData(&yaw,&pitch,&roll);  //读取传感器姿态 
00026         pc.printf("Yaw, Pitch, Roll: %f %f %f\n\r", yaw, pitch, roll);
00027     }
00028  }