Let me know what you think
Dependencies: BLE_API mbed nRF51822
Fork of SDP_Version3_Abdul by
MMA8452Q.h
00001 // Library for our MMA8452Q 3-axis accelerometer 00002 // Based on the MMA8452Q Arduino Library by Jim Lindblom (SparkFun Electronics) 00003 00004 #ifndef MMA8452Q_H 00005 #define MMA8452Q_H 00006 00007 #include "mbed.h" 00008 00009 // Register definitions 00010 #define REG_STATUS 0x00 00011 #define OUT_X_MSB 0x01 00012 #define OUT_X_LSB 0x02 00013 #define OUT_Y_MSB 0x03 00014 #define OUT_Y_LSB 0x04 00015 #define OUT_Z_MSB 0x05 00016 #define OUT_Z_LSB 0x06 00017 #define REG_WHO_AM_I 0x0D 00018 #define REG_XYZ_DATA_CFG 0x0E 00019 #define REG_CTRL_REG1 0x2A 00020 #define MMA8452_STATUS_ZYXDR_MASK 0x08 00021 00022 // WHO_AM_I check 00023 #define FACTORY_ID 0x2A 00024 00025 // Scale definitions 00026 #define SCALE_2G 2 00027 #define SCALE_4G 4 00028 #define SCALE_8G 8 00029 00030 // Data rates 00031 #define ODR_800HZ 0 00032 #define ODR_400HZ 1 00033 #define ODR_200HZ 2 00034 #define ODR_100HZ 3 00035 #define ODR_50HZ 4 00036 #define ODR_12_5HZ 5 00037 #define ODR_6_25HZ 6 00038 #define ODR_1_56HZ 7 00039 00040 // Init values 00041 #define DEFAULT_FSR SCALE_2G 00042 #define DEFAULT_ODR ODR_800HZ 00043 00044 00045 // Class declaration 00046 class MMA8452Q 00047 { 00048 public: 00049 MMA8452Q(PinName sda, PinName scl, int addr); 00050 ~MMA8452Q(); 00051 bool init(); 00052 //uint8_t available(); 00053 bool available(); 00054 void setScale(uint8_t fsr); 00055 void setODR(uint8_t odr); 00056 void standby(); 00057 void active(); 00058 float readX(); 00059 float readY(); 00060 float readZ(); 00061 int isXYZReady(); 00062 //char available(); 00063 char getMaskedRegister(int addr, char mask); 00064 uint8_t readRegister(uint8_t reg); 00065 void writeRegister(uint8_t reg, uint8_t data); 00066 00067 private: 00068 I2C m_i2c; 00069 int m_addr; 00070 int scale; 00071 }; 00072 00073 #endif
Generated on Thu Jul 21 2022 03:56:02 by
1.7.2
