加速度センサMPU6050 サンプルプログラムでは、xyz軸の加速度を表示します。
Dependencies: mbed MPU6050 Math
Fork of MPU6050_cansat by
main.cpp@3:157b19421485, 2018-10-29 (annotated)
- Committer:
- falconsyunya
- Date:
- Mon Oct 29 12:22:57 2018 +0000
- Revision:
- 3:157b19421485
- Parent:
- 1:958b581f6d21
- Child:
- 4:d2bb399c7c8c
?????????
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
falconsyunya | 0:4ba3fa671062 | 1 | #include "mbed.h" |
falconsyunya | 0:4ba3fa671062 | 2 | #include "MPU6050.h" |
falconsyunya | 0:4ba3fa671062 | 3 | |
falconsyunya | 0:4ba3fa671062 | 4 | DigitalOut myled(LED1); |
falconsyunya | 3:157b19421485 | 5 | MPU6050 mpu(p9,p10);//(SDA,SCL)のピン配置 |
falconsyunya | 0:4ba3fa671062 | 6 | |
falconsyunya | 0:4ba3fa671062 | 7 | int main() { |
falconsyunya | 0:4ba3fa671062 | 8 | while(1){ |
falconsyunya | 1:958b581f6d21 | 9 | float accel[3];//accelを3つの配列で定義。 |
falconsyunya | 1:958b581f6d21 | 10 | mpu.readAccelData(accel);//加速度の値をaccel[3]に代入 |
falconsyunya | 1:958b581f6d21 | 11 | float x = accel[0]/16384;//x軸方向の加速度 |
falconsyunya | 1:958b581f6d21 | 12 | float y = accel[1]/16384;//y軸方向の加速度 |
falconsyunya | 1:958b581f6d21 | 13 | float z = accel[2]/16384;//z軸方向の加速度 |
falconsyunya | 3:157b19421485 | 14 | printf("accel x:%f y:%f z:%f\r\n",x,y,z);//加速度の表示 |
falconsyunya | 3:157b19421485 | 15 | wait(0.1); |
falconsyunya | 0:4ba3fa671062 | 16 | } |
falconsyunya | 0:4ba3fa671062 | 17 | } |