my new gear...

Dependencies:   mbed

Committer:
yootee
Date:
Sun Mar 27 04:51:16 2022 +0000
Revision:
3:a9b4b2565a23
my new gear...

Who changed what in which revision?

UserRevisionLine numberNew contents of line
yootee 3:a9b4b2565a23 1 #ifndef GY521_H
yootee 3:a9b4b2565a23 2 #define GY521_H
yootee 3:a9b4b2565a23 3 #include "mbed.h"
yootee 3:a9b4b2565a23 4
yootee 3:a9b4b2565a23 5 /*GY521を使う。
yootee 3:a9b4b2565a23 6 *I2Cオブジェクトを渡す
yootee 3:a9b4b2565a23 7 *GY521(I2C &i2c,int bit = 2,int calibration = 1000,double user_reg = 1.0);
yootee 3:a9b4b2565a23 8 *example
yootee 3:a9b4b2565a23 9 *L432KC : SDA = PB_7 , SCL = PB_6
yootee 3:a9b4b2565a23 10 *F446RE : SDA = PB_3 , SCL = PB_10
yootee 3:a9b4b2565a23 11 *ループ内で毎回
yootee 3:a9b4b2565a23 12 *<obj>.update()
yootee 3:a9b4b2565a23 13 *を呼び出してください。
yootee 3:a9b4b2565a23 14 */
yootee 3:a9b4b2565a23 15 //I2C i2c(SDA,SCL);
yootee 3:a9b4b2565a23 16 //GY521 gyro(i2c);
yootee 3:a9b4b2565a23 17
yootee 3:a9b4b2565a23 18 enum GY521RegisterMap {
yootee 3:a9b4b2565a23 19 WHO_AM_I = 0x75,
yootee 3:a9b4b2565a23 20 PWR_MGMT_1 = 0x6B,
yootee 3:a9b4b2565a23 21 LPF = 0x1A,
yootee 3:a9b4b2565a23 22 FS_SEL = 0x1B,
yootee 3:a9b4b2565a23 23 AFS_SEL = 0x1C,
yootee 3:a9b4b2565a23 24 ACCEL_XOUT_H = 0x3B,
yootee 3:a9b4b2565a23 25 ACCEL_YOUT_H = 0x3D,
yootee 3:a9b4b2565a23 26 ACCEL_ZOUT_H = 0x3F,
yootee 3:a9b4b2565a23 27 //TEMPERATURE = 0x41,
yootee 3:a9b4b2565a23 28 //GYRO_XOUT_H = 0x43,
yootee 3:a9b4b2565a23 29 //GYRO_YOUT_H = 0x45,
yootee 3:a9b4b2565a23 30 GYRO_ZOUT_H = 0x47
yootee 3:a9b4b2565a23 31 };
yootee 3:a9b4b2565a23 32
yootee 3:a9b4b2565a23 33 class GY521{
yootee 3:a9b4b2565a23 34 public:
yootee 3:a9b4b2565a23 35 GY521(I2C &i2c,int bit = 2,int calibration = 1000,double user_reg = 1.0);
yootee 3:a9b4b2565a23 36 double yaw;
yootee 3:a9b4b2565a23 37 //double temp;
yootee 3:a9b4b2565a23 38 void update();
yootee 3:a9b4b2565a23 39 void reset(int user);
yootee 3:a9b4b2565a23 40 void start(double start = 0){
yootee 3:a9b4b2565a23 41 yaw = start;
yootee 3:a9b4b2565a23 42 }
yootee 3:a9b4b2565a23 43 double checkStatus(int mode);
yootee 3:a9b4b2565a23 44 private:
yootee 3:a9b4b2565a23 45 I2C &i2c_;
yootee 3:a9b4b2565a23 46 Timer timer_;
yootee 3:a9b4b2565a23 47 int16_t gyroRead2(enum GY521RegisterMap reg);
yootee 3:a9b4b2565a23 48 double gyro_z_aver_;
yootee 3:a9b4b2565a23 49 double gyro_z_now_;
yootee 3:a9b4b2565a23 50 double gyro_z_prev_;
yootee 3:a9b4b2565a23 51 double gyro_LSB_;
yootee 3:a9b4b2565a23 52 double diff_yaw_;
yootee 3:a9b4b2565a23 53 int bit_;
yootee 3:a9b4b2565a23 54 int calibration_;
yootee 3:a9b4b2565a23 55 bool flag_;
yootee 3:a9b4b2565a23 56 };
yootee 3:a9b4b2565a23 57
yootee 3:a9b4b2565a23 58 #endif /* GY521_H */