I2C interface for LG1300L IMU
Dependents: LG1300L_Hello_World LG1300L_Hello_World_LCD
LG1300L.h
- Committer:
- mjenkins11
- Date:
- 2013-03-05
- Revision:
- 0:896f1d7a0503
- Child:
- 1:c40e8dead9be
File content as of revision 0:896f1d7a0503:
#include "mbed.h" #ifndef MBED_LG1300L_H #define MBED_LG1300L_H /*! CruizCore XG1300L IMU interface * Used for communicating with an XG1300L IMU over I2C * @code *#include "mbed.h" *#include "TextLCD.h" *#include "LG1300L.h" * *TextLCD lcd(p15, p16, p17, p18, p19, p20); // rs, e, d4-d7 * *Serial pc(USBTX, USBRX); // tx, rx * *I2C i2c(p28,p27); *DigitalOut LED (LED1); * *int main() { * LG1300L IMU(i2c, 2); * * while(1) { * float angle = IMU.GetAngle(); * float ROT= IMU.GetROT(); * float X_ACC = IMU.GetACC_X(); * float Y_ACC = IMU. GetACC_Y(); * float Z_ACC = IMU. GetACC_Z(); * pc.printf("///////////////////////////////////\n"); * pc.printf("//ANGLE: %f\n", angle); * pc.printf("//ROT: %f\n", ROT); * pc.printf("//X-Axis: %f\n", X_ACC ); * pc.printf("//Y-Axis: %f\n", Y_ACC ); * pc.printf("//Z-axis: %f\n", Z_ACC ); * pc.printf("///////////////////////////////////\n"); * wait(1); * } *} * @endcode */ class LG1300L{ public: /*! Create an IMU readout interface * * @param i2c The instantiated I2C bus to be used * @param ACC_SETTING the desired initialization range for the accelerometers, choices are +-2G, +-4G, or +-8G */ LG1300L(I2C& i2c, int ACC_SETTING); /*! Returns a float containing the current Accumulated Angle * @returns float */ float GetAngle(); /*! Returns a float containing the current ROT * @returns float */ float GetROT(); /*! Returns a float containing the current acceleration on * the X axis. * @returns float * */ float GetACC_X(); /*! Returns a float containing the current acceleration on *the Y axis. * @returns float */ float GetACC_Y(); /*! Returns a float containing the current acceleration on *the Z axis. * @returns float */ float GetACC_Z(); private: void init(); char ANGLE_LSB_REG[1]; char ANGLE_MSB_REG[1]; char ROT_LSB_REG[1]; char ROT_MSB_REG[1]; char X_ACC_LSB_REG[1]; char X_ACC_MSB_REG[1]; char Y_ACC_LSB_REG[1]; char Y_ACC_MSB_REG[1]; char Z_ACC_LSB_REG[1]; char Z_ACC_MSB_REG[1]; char RESET_REG[1]; char SELECT_2G_REG[1]; char SELECT_4G_REG[1]; char SELECT_8G_REG[1]; float CALC_ANG, CALC_ROT, CALC_X, CALC_Y, CALC_Z; int ACC_RANGE; signed short ANGLE_MSB; signed short ANGLE_LSB; signed short ROT_MSB; signed short ROT_LSB; signed short ACC_X_MSB; signed short ACC_X_LSB; signed short ACC_Y_MSB; signed short ACC_Y_LSB; signed short ACC_Z_MSB; signed short ACC_Z_LSB; protected: I2C& IMU; char data[2]; const int IMU_ADDR; }; #endif