![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
I2C通信を使用した角速度測定、LCD表示サンプル
Dependencies: mbed mbed_mpu6050_i2c_raw_register AQM0802
main.cpp@1:6f743fe9a027, 2018-12-13 (annotated)
- Committer:
- satoshi1204
- Date:
- Thu Dec 13 03:00:27 2018 +0000
- Revision:
- 1:6f743fe9a027
- Parent:
- 0:abd3a0fd55a9
- Child:
- 2:f2db52a742b0
support sleep function for MPU-6050
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
satoshi1204 | 0:abd3a0fd55a9 | 1 | #include "mbed.h" |
satoshi1204 | 0:abd3a0fd55a9 | 2 | #include "mpu6050.h" |
satoshi1204 | 0:abd3a0fd55a9 | 3 | |
satoshi1204 | 0:abd3a0fd55a9 | 4 | Serial pc(USBTX, USBRX); |
satoshi1204 | 1:6f743fe9a027 | 5 | DigitalOut led1(LED1); |
satoshi1204 | 1:6f743fe9a027 | 6 | DigitalOut led2(LED2); |
satoshi1204 | 1:6f743fe9a027 | 7 | DigitalOut led3(LED3); |
satoshi1204 | 1:6f743fe9a027 | 8 | DigitalOut led4(LED4); |
satoshi1204 | 0:abd3a0fd55a9 | 9 | MPU6050 mpu(p9, p10); |
satoshi1204 | 0:abd3a0fd55a9 | 10 | |
satoshi1204 | 0:abd3a0fd55a9 | 11 | void readData() |
satoshi1204 | 0:abd3a0fd55a9 | 12 | { |
satoshi1204 | 0:abd3a0fd55a9 | 13 | double ax, ay, az; |
satoshi1204 | 0:abd3a0fd55a9 | 14 | mpu.readAccelemeter(ax, ay, az); |
satoshi1204 | 0:abd3a0fd55a9 | 15 | double gx, gy, gz; |
satoshi1204 | 0:abd3a0fd55a9 | 16 | mpu.readGyroscope(gx, gy, gz); |
satoshi1204 | 0:abd3a0fd55a9 | 17 | pc.printf("%.4lf %.4lf %.4lf %.4lf %.4lf %.4lf\r\n", ax, ay, az, gx, gy, gz); |
satoshi1204 | 0:abd3a0fd55a9 | 18 | } |
satoshi1204 | 0:abd3a0fd55a9 | 19 | |
satoshi1204 | 0:abd3a0fd55a9 | 20 | int main() { |
satoshi1204 | 0:abd3a0fd55a9 | 21 | mpu.setMaxScale(MAX_ACC_8G, MAX_GYRO_1000degpersec); |
satoshi1204 | 0:abd3a0fd55a9 | 22 | while(1) { |
satoshi1204 | 1:6f743fe9a027 | 23 | led1 = 1; |
satoshi1204 | 0:abd3a0fd55a9 | 24 | readData(); |
satoshi1204 | 0:abd3a0fd55a9 | 25 | wait(0.2); |
satoshi1204 | 1:6f743fe9a027 | 26 | led1 = 0; |
satoshi1204 | 0:abd3a0fd55a9 | 27 | wait(0.2); |
satoshi1204 | 0:abd3a0fd55a9 | 28 | } |
satoshi1204 | 0:abd3a0fd55a9 | 29 | } |