I2C通信を使用した角速度測定、LCD表示サンプル
Dependencies: mbed mbed_mpu6050_i2c_raw_register AQM0802
mpu6050.h@0:abd3a0fd55a9, 2018-12-12 (annotated)
- Committer:
- satoshi1204
- Date:
- Wed Dec 12 12:42:30 2018 +0000
- Revision:
- 0:abd3a0fd55a9
- Child:
- 1:6f743fe9a027
implement MPU library
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 | |
satoshi1204 | 0:abd3a0fd55a9 | 3 | enum { |
satoshi1204 | 0:abd3a0fd55a9 | 4 | MAX_ACC_2G, |
satoshi1204 | 0:abd3a0fd55a9 | 5 | MAX_ACC_4G, |
satoshi1204 | 0:abd3a0fd55a9 | 6 | MAX_ACC_8G, |
satoshi1204 | 0:abd3a0fd55a9 | 7 | MAX_ACC_16G, |
satoshi1204 | 0:abd3a0fd55a9 | 8 | }; |
satoshi1204 | 0:abd3a0fd55a9 | 9 | |
satoshi1204 | 0:abd3a0fd55a9 | 10 | enum { |
satoshi1204 | 0:abd3a0fd55a9 | 11 | MAX_GYRO_250degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 12 | MAX_GYRO_500degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 13 | MAX_GYRO_1000degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 14 | MAX_GYRO_2000degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 15 | }; |
satoshi1204 | 0:abd3a0fd55a9 | 16 | |
satoshi1204 | 0:abd3a0fd55a9 | 17 | class MPU6050 |
satoshi1204 | 0:abd3a0fd55a9 | 18 | { |
satoshi1204 | 0:abd3a0fd55a9 | 19 | public: |
satoshi1204 | 0:abd3a0fd55a9 | 20 | MPU6050(PinName i2c_sda, PinName i2c_scl); |
satoshi1204 | 0:abd3a0fd55a9 | 21 | ~MPU6050(); |
satoshi1204 | 0:abd3a0fd55a9 | 22 | void readAccelemeter(double &acc_x, double &acc_y, double &acc_z); |
satoshi1204 | 0:abd3a0fd55a9 | 23 | void readGyroscope(double &gyro_x, double &gyro_y, double &gyro_z); |
satoshi1204 | 0:abd3a0fd55a9 | 24 | void setMaxScale(int max_acc, int max_gyro); |
satoshi1204 | 0:abd3a0fd55a9 | 25 | void getMaxScale(int &acc, int &gyro); |
satoshi1204 | 0:abd3a0fd55a9 | 26 | private: |
satoshi1204 | 0:abd3a0fd55a9 | 27 | I2C i2c; |
satoshi1204 | 0:abd3a0fd55a9 | 28 | int address; |
satoshi1204 | 0:abd3a0fd55a9 | 29 | double rate_accelemeter; |
satoshi1204 | 0:abd3a0fd55a9 | 30 | double rate_gyroscope; |
satoshi1204 | 0:abd3a0fd55a9 | 31 | char readByte(char reg); |
satoshi1204 | 0:abd3a0fd55a9 | 32 | void writeByte(char reg, char data); |
satoshi1204 | 0:abd3a0fd55a9 | 33 | }; |