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.
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 00021 // WHO_AM_I check 00022 #define FACTORY_ID 0x2A 00023 00024 // Scale definitions 00025 #define SCALE_2G 2 00026 #define SCALE_4G 4 00027 #define SCALE_8G 8 00028 00029 // Data rates 00030 #define ODR_800HZ 0 00031 #define ODR_400HZ 1 00032 #define ODR_200HZ 2 00033 #define ODR_100HZ 3 00034 #define ODR_50HZ 4 00035 #define ODR_12_5HZ 5 00036 #define ODR_6_25HZ 6 00037 #define ODR_1_56HZ 7 00038 00039 // Init values 00040 #define DEFAULT_FSR SCALE_2G 00041 #define DEFAULT_ODR ODR_800HZ 00042 00043 00044 // Class declaration 00045 class MMA8452Q 00046 { 00047 public: 00048 MMA8452Q(PinName sda, PinName scl, int addr); 00049 ~MMA8452Q(); 00050 bool init(); 00051 uint8_t available(); 00052 void setScale(uint8_t fsr); 00053 void setODR(uint8_t odr); 00054 void standby(); 00055 void active(); 00056 float readX(); 00057 float readY(); 00058 float readZ(); 00059 uint8_t readRegister(uint8_t reg); 00060 void writeRegister(uint8_t reg, uint8_t data); 00061 00062 private: 00063 I2C m_i2c; 00064 int m_addr; 00065 int scale; 00066 }; 00067 00068 #endif
Generated on Sat Jul 16 2022 22:29:37 by
1.7.2