Chen Huan
/
MPU6050_Driver_Balance
平衡车的MPU6050驱动 C.H.
main.cpp@0:badebd32bd8b, 2018-04-09 (annotated)
- Committer:
- heroistired
- Date:
- Mon Apr 09 14:34:45 2018 +0000
- Revision:
- 0:badebd32bd8b
????MPU6050?? ; C.H.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
heroistired | 0:badebd32bd8b | 1 | #include "mbed.h" |
heroistired | 0:badebd32bd8b | 2 | #include "mpu6050.h" |
heroistired | 0:badebd32bd8b | 3 | |
heroistired | 0:badebd32bd8b | 4 | |
heroistired | 0:badebd32bd8b | 5 | DigitalOut myled(LED1); |
heroistired | 0:badebd32bd8b | 6 | Serial pc(SERIAL_TX, SERIAL_RX); |
heroistired | 0:badebd32bd8b | 7 | |
heroistired | 0:badebd32bd8b | 8 | int main() { |
heroistired | 0:badebd32bd8b | 9 | float pitch,roll,yaw; //欧拉角 |
heroistired | 0:badebd32bd8b | 10 | |
heroistired | 0:badebd32bd8b | 11 | MPU_Init(); //初始化MPU6050 |
heroistired | 0:badebd32bd8b | 12 | myled = 0; |
heroistired | 0:badebd32bd8b | 13 | while(mpu_dmp_init()) |
heroistired | 0:badebd32bd8b | 14 | { |
heroistired | 0:badebd32bd8b | 15 | wait(0.2); |
heroistired | 0:badebd32bd8b | 16 | myled = !myled; |
heroistired | 0:badebd32bd8b | 17 | } |
heroistired | 0:badebd32bd8b | 18 | while(1) |
heroistired | 0:badebd32bd8b | 19 | { |
heroistired | 0:badebd32bd8b | 20 | if(mpu_dmp_get_data(&pitch,&roll,&yaw)==0)//获取欧拉角 |
heroistired | 0:badebd32bd8b | 21 | { |
heroistired | 0:badebd32bd8b | 22 | pc.printf("pitch: %.2f roll: %.2f yaw: %.2f\r\n", pitch,roll,yaw); |
heroistired | 0:badebd32bd8b | 23 | } |
heroistired | 0:badebd32bd8b | 24 | } |
heroistired | 0:badebd32bd8b | 25 | } |