I2C通信を使用した角速度測定、LCD表示サンプル
Dependencies: mbed mbed_mpu6050_i2c_raw_register AQM0802
MPU6050/mpu6050.h@6:c940ad83d2c5, 2019-07-22 (annotated)
- Committer:
- yusaku0125
- Date:
- Mon Jul 22 09:43:17 2019 +0000
- Revision:
- 6:c940ad83d2c5
- Parent:
- 4:bf507fe18cb2
test
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 | 1:6f743fe9a027 | 3 | #ifndef MPU6050_H |
satoshi1204 | 1:6f743fe9a027 | 4 | #define MPU6050_H |
satoshi1204 | 1:6f743fe9a027 | 5 | |
satoshi1204 | 0:abd3a0fd55a9 | 6 | enum { |
satoshi1204 | 0:abd3a0fd55a9 | 7 | MAX_ACC_2G, |
satoshi1204 | 0:abd3a0fd55a9 | 8 | MAX_ACC_4G, |
satoshi1204 | 0:abd3a0fd55a9 | 9 | MAX_ACC_8G, |
satoshi1204 | 0:abd3a0fd55a9 | 10 | MAX_ACC_16G, |
satoshi1204 | 0:abd3a0fd55a9 | 11 | }; |
satoshi1204 | 0:abd3a0fd55a9 | 12 | |
satoshi1204 | 0:abd3a0fd55a9 | 13 | enum { |
satoshi1204 | 0:abd3a0fd55a9 | 14 | MAX_GYRO_250degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 15 | MAX_GYRO_500degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 16 | MAX_GYRO_1000degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 17 | MAX_GYRO_2000degpersec, |
satoshi1204 | 0:abd3a0fd55a9 | 18 | }; |
satoshi1204 | 0:abd3a0fd55a9 | 19 | |
satoshi1204 | 0:abd3a0fd55a9 | 20 | class MPU6050 |
satoshi1204 | 0:abd3a0fd55a9 | 21 | { |
satoshi1204 | 0:abd3a0fd55a9 | 22 | public: |
satoshi1204 | 0:abd3a0fd55a9 | 23 | MPU6050(PinName i2c_sda, PinName i2c_scl); |
satoshi1204 | 0:abd3a0fd55a9 | 24 | ~MPU6050(); |
satoshi1204 | 0:abd3a0fd55a9 | 25 | void readAccelemeter(double &acc_x, double &acc_y, double &acc_z); |
satoshi1204 | 0:abd3a0fd55a9 | 26 | void readGyroscope(double &gyro_x, double &gyro_y, double &gyro_z); |
satoshi1204 | 0:abd3a0fd55a9 | 27 | void setMaxScale(int max_acc, int max_gyro); |
satoshi1204 | 0:abd3a0fd55a9 | 28 | void getMaxScale(int &acc, int &gyro); |
satoshi1204 | 1:6f743fe9a027 | 29 | void setSleep(bool sleep); |
satoshi1204 | 0:abd3a0fd55a9 | 30 | private: |
satoshi1204 | 0:abd3a0fd55a9 | 31 | I2C i2c; |
satoshi1204 | 0:abd3a0fd55a9 | 32 | int address; |
satoshi1204 | 0:abd3a0fd55a9 | 33 | double rate_accelemeter; |
satoshi1204 | 0:abd3a0fd55a9 | 34 | double rate_gyroscope; |
satoshi1204 | 0:abd3a0fd55a9 | 35 | char readByte(char reg); |
satoshi1204 | 0:abd3a0fd55a9 | 36 | void writeByte(char reg, char data); |
satoshi1204 | 0:abd3a0fd55a9 | 37 | }; |
satoshi1204 | 1:6f743fe9a027 | 38 | |
satoshi1204 | 1:6f743fe9a027 | 39 | #endif // MPU6050_H |