加速度センサのプログラムです(zの政府で判断、PCに表示)
Dependencies: mbed
mpu6050.cpp@1:8d3dd0d73048, 2019-11-19 (annotated)
- Committer:
- Nryo
- Date:
- Tue Nov 19 06:01:35 2019 +0000
- Revision:
- 1:8d3dd0d73048
- Parent:
- 0:d8462d09ff84
MPU6050
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MIKUNAGATA | 0:d8462d09ff84 | 1 | #include "mbed.h" |
Nryo | 1:8d3dd0d73048 | 2 | #include "mpu6050.h" |
MIKUNAGATA | 0:d8462d09ff84 | 3 | |
Nryo | 1:8d3dd0d73048 | 4 | |
MIKUNAGATA | 0:d8462d09ff84 | 5 | MPU6050 mpu(p9,p10); |
MIKUNAGATA | 0:d8462d09ff84 | 6 | |
MIKUNAGATA | 0:d8462d09ff84 | 7 | int main() { |
MIKUNAGATA | 0:d8462d09ff84 | 8 | |
Nryo | 1:8d3dd0d73048 | 9 | int accel[3];//accを定義。 |
MIKUNAGATA | 0:d8462d09ff84 | 10 | while(1){ |
MIKUNAGATA | 0:d8462d09ff84 | 11 | mpu.readAccelData(accel);//加速度の値をacc[3]に代入 |
Nryo | 1:8d3dd0d73048 | 12 | int x = accel[0];//x軸方向の加速度 |
Nryo | 1:8d3dd0d73048 | 13 | int y = accel[1];//y軸方向の加速度 |
Nryo | 1:8d3dd0d73048 | 14 | int z = accel[2];//z軸方向の加速度 |
MIKUNAGATA | 0:d8462d09ff84 | 15 | |
MIKUNAGATA | 0:d8462d09ff84 | 16 | printf("x:%06d y:%06d z:%06d\r\n",x,y,z); |
MIKUNAGATA | 0:d8462d09ff84 | 17 | wait(0.01); |
MIKUNAGATA | 0:d8462d09ff84 | 18 | } |
MIKUNAGATA | 0:d8462d09ff84 | 19 | } |