Updated OCE 360 Assignment 4
Dependents: Barros_Assignment4
MMA8452Q.h@2:1d10bcf263d2, 2017-12-07 (annotated)
- Committer:
- Kaitlyn_Barros
- Date:
- Thu Dec 07 23:20:41 2017 +0000
- Revision:
- 2:1d10bcf263d2
- Parent:
- 0:098406435cd2
Assignment 6. Attempt to employ free fall register.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Kaitlyn_Barros | 0:098406435cd2 | 1 | // Library for our MMA8452Q 3-axis accelerometer |
Kaitlyn_Barros | 0:098406435cd2 | 2 | // Based on the MMA8452Q Arduino Library by Jim Lindblom (SparkFun Electronics) |
Kaitlyn_Barros | 0:098406435cd2 | 3 | |
Kaitlyn_Barros | 0:098406435cd2 | 4 | #ifndef MMA8452Q_H |
Kaitlyn_Barros | 0:098406435cd2 | 5 | #define MMA8452Q_H |
Kaitlyn_Barros | 0:098406435cd2 | 6 | |
Kaitlyn_Barros | 0:098406435cd2 | 7 | #include "mbed.h" |
Kaitlyn_Barros | 0:098406435cd2 | 8 | |
Kaitlyn_Barros | 0:098406435cd2 | 9 | // Register definitions |
Kaitlyn_Barros | 0:098406435cd2 | 10 | #define REG_STATUS 0x00 |
Kaitlyn_Barros | 0:098406435cd2 | 11 | #define OUT_X_MSB 0x01 |
Kaitlyn_Barros | 0:098406435cd2 | 12 | #define OUT_X_LSB 0x02 |
Kaitlyn_Barros | 0:098406435cd2 | 13 | #define OUT_Y_MSB 0x03 |
Kaitlyn_Barros | 0:098406435cd2 | 14 | #define OUT_Y_LSB 0x04 |
Kaitlyn_Barros | 0:098406435cd2 | 15 | #define OUT_Z_MSB 0x05 |
Kaitlyn_Barros | 0:098406435cd2 | 16 | #define OUT_Z_LSB 0x06 |
Kaitlyn_Barros | 0:098406435cd2 | 17 | #define REG_WHO_AM_I 0x0D |
Kaitlyn_Barros | 0:098406435cd2 | 18 | #define REG_XYZ_DATA_CFG 0x0E |
Kaitlyn_Barros | 0:098406435cd2 | 19 | #define REG_CTRL_REG1 0x2A |
Kaitlyn_Barros | 2:1d10bcf263d2 | 20 | #define REG_FF_MT_CFG 0x15 |
Kaitlyn_Barros | 0:098406435cd2 | 21 | |
Kaitlyn_Barros | 0:098406435cd2 | 22 | // WHO_AM_I check |
Kaitlyn_Barros | 0:098406435cd2 | 23 | #define FACTORY_ID 0x2A |
Kaitlyn_Barros | 0:098406435cd2 | 24 | |
Kaitlyn_Barros | 0:098406435cd2 | 25 | // Scale definitions |
Kaitlyn_Barros | 0:098406435cd2 | 26 | #define SCALE_2G 2 |
Kaitlyn_Barros | 0:098406435cd2 | 27 | #define SCALE_4G 4 |
Kaitlyn_Barros | 0:098406435cd2 | 28 | #define SCALE_8G 8 |
Kaitlyn_Barros | 0:098406435cd2 | 29 | |
Kaitlyn_Barros | 0:098406435cd2 | 30 | // Data rates |
Kaitlyn_Barros | 0:098406435cd2 | 31 | #define ODR_800HZ 0 |
Kaitlyn_Barros | 0:098406435cd2 | 32 | #define ODR_400HZ 1 |
Kaitlyn_Barros | 0:098406435cd2 | 33 | #define ODR_200HZ 2 |
Kaitlyn_Barros | 0:098406435cd2 | 34 | #define ODR_100HZ 3 |
Kaitlyn_Barros | 0:098406435cd2 | 35 | #define ODR_50HZ 4 |
Kaitlyn_Barros | 0:098406435cd2 | 36 | #define ODR_12_5HZ 5 |
Kaitlyn_Barros | 0:098406435cd2 | 37 | #define ODR_6_25HZ 6 |
Kaitlyn_Barros | 0:098406435cd2 | 38 | #define ODR_1_56HZ 7 |
Kaitlyn_Barros | 0:098406435cd2 | 39 | |
Kaitlyn_Barros | 0:098406435cd2 | 40 | // Init values |
Kaitlyn_Barros | 0:098406435cd2 | 41 | #define DEFAULT_FSR SCALE_2G |
Kaitlyn_Barros | 0:098406435cd2 | 42 | #define DEFAULT_ODR ODR_800HZ |
Kaitlyn_Barros | 0:098406435cd2 | 43 | |
Kaitlyn_Barros | 0:098406435cd2 | 44 | |
Kaitlyn_Barros | 0:098406435cd2 | 45 | // Class declaration |
Kaitlyn_Barros | 0:098406435cd2 | 46 | class MMA8452Q |
Kaitlyn_Barros | 0:098406435cd2 | 47 | { |
Kaitlyn_Barros | 0:098406435cd2 | 48 | public: |
Kaitlyn_Barros | 0:098406435cd2 | 49 | MMA8452Q(PinName sda, PinName scl, int addr); |
Kaitlyn_Barros | 0:098406435cd2 | 50 | ~MMA8452Q(); |
Kaitlyn_Barros | 0:098406435cd2 | 51 | bool init(); |
Kaitlyn_Barros | 0:098406435cd2 | 52 | uint8_t available(); |
Kaitlyn_Barros | 0:098406435cd2 | 53 | void setScale(uint8_t fsr); |
Kaitlyn_Barros | 0:098406435cd2 | 54 | void setODR(uint8_t odr); |
Kaitlyn_Barros | 0:098406435cd2 | 55 | void standby(); |
Kaitlyn_Barros | 0:098406435cd2 | 56 | void active(); |
Kaitlyn_Barros | 2:1d10bcf263d2 | 57 | void standby1(); |
Kaitlyn_Barros | 2:1d10bcf263d2 | 58 | void active1(); |
Kaitlyn_Barros | 0:098406435cd2 | 59 | float readX(); |
Kaitlyn_Barros | 0:098406435cd2 | 60 | float readY(); |
Kaitlyn_Barros | 0:098406435cd2 | 61 | float readZ(); |
Kaitlyn_Barros | 0:098406435cd2 | 62 | uint8_t readRegister(uint8_t reg); |
Kaitlyn_Barros | 0:098406435cd2 | 63 | void writeRegister(uint8_t reg, uint8_t data); |
Kaitlyn_Barros | 0:098406435cd2 | 64 | |
Kaitlyn_Barros | 0:098406435cd2 | 65 | private: |
Kaitlyn_Barros | 0:098406435cd2 | 66 | I2C m_i2c; |
Kaitlyn_Barros | 0:098406435cd2 | 67 | int m_addr; |
Kaitlyn_Barros | 0:098406435cd2 | 68 | int scale; |
Kaitlyn_Barros | 0:098406435cd2 | 69 | }; |
Kaitlyn_Barros | 0:098406435cd2 | 70 | |
Kaitlyn_Barros | 0:098406435cd2 | 71 | #endif |