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