Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
gy521.hpp
00001 #ifndef GY521_H 00002 #define GY521_H 00003 #include "mbed.h" 00004 00005 /*GY521を使う。 00006 *I2Cオブジェクトを渡す 00007 *GY521(I2C &i2c,int bit = 2,int calibration = 1000,double user_reg = 1.0); 00008 *example 00009 *L432KC : SDA = PB_7 , SCL = PB_6 00010 *F446RE : SDA = PB_3 , SCL = PB_10 00011 *ループ内で毎回 00012 *<obj>.update() 00013 *を呼び出してください。 00014 */ 00015 //I2C i2c(SDA,SCL); 00016 //GY521 gyro(i2c); 00017 00018 enum GY521RegisterMap { 00019 WHO_AM_I = 0x75, 00020 PWR_MGMT_1 = 0x6B, 00021 LPF = 0x1A, 00022 FS_SEL = 0x1B, 00023 AFS_SEL = 0x1C, 00024 ACCEL_XOUT_H = 0x3B, 00025 ACCEL_YOUT_H = 0x3D, 00026 ACCEL_ZOUT_H = 0x3F, 00027 //TEMPERATURE = 0x41, 00028 //GYRO_XOUT_H = 0x43, 00029 //GYRO_YOUT_H = 0x45, 00030 GYRO_ZOUT_H = 0x47 00031 }; 00032 00033 class GY521{ 00034 public: 00035 GY521(I2C &i2c,int bit = 2,int calibration = 1000,double user_reg = 1.0); 00036 double yaw; 00037 //double temp; 00038 void update(); 00039 void reset(int user); 00040 void start(double start = 0){ 00041 yaw = start; 00042 } 00043 double checkStatus(int mode); 00044 private: 00045 I2C &i2c_; 00046 Timer timer_; 00047 int16_t gyroRead2(enum GY521RegisterMap reg); 00048 double gyro_z_aver_; 00049 double gyro_z_now_; 00050 double gyro_z_prev_; 00051 double gyro_LSB_; 00052 double diff_yaw_; 00053 int bit_; 00054 int calibration_; 00055 bool flag_; 00056 }; 00057 00058 #endif /* GY521_H */
Generated on Sat Oct 15 2022 07:52:33 by
1.7.2