Bruno Allaire-Lemay
/
APP1test
df
Fork of APP1 by
Accelerometer.hpp
- Committer:
- dupm2216
- Date:
- 2017-01-14
- Revision:
- 3:1a9d0f0a50bf
- Parent:
- 1:7becb0e903e3
- Child:
- 4:303fb83498fd
File content as of revision 3:1a9d0f0a50bf:
#ifndef ACCELEROMETER_HPP #define ACCELEROMETER_HPP #include "mbed.h" const int NUMBER_OF_DATA_REGISTERS = 6; const char OUT_X_MSB_REGISTER = 0x01; const char OUT_X_LSB_REGISTER = 0x02; const char OUT_Y_MSB_REGISTER = 0x03; const char OUT_Y_LSB_REGISTER = 0x04; const char OUT_Z_MSB_REGISTER = 0x05; const char OUT_Z_LSB_REGISTER = 0x06; const char WHO_AM_I_REGISTER = 0x0D; const char CTRL_REG1_REGISTER_ADDRESS = 0x2A; const int I2C_ACCELEROMETER_ADDRESS = 0x1D; enum Axis { AXIS_X, AXIS_Y, AXIS_Z, AXIS_INVALID }; int raw_axis_data_to_int(signed char raw_axis_data); void test_raw_axis_data_to_int(); char get_axis_register(Axis axis); class Accelerometer { public: Accelerometer( PinName sda_pin, PinName scl_pin, const int slave_address = I2C_ACCELEROMETER_ADDRESS ); void write_register(const char register_address, const char new_value); char read_register(const char register_address); //axis_data must be an array of length 6 void read_all_axis(signed char* axis_data); void print_all_axis_data(); void set_standby(); void set_active(); void init(); //Read data from the 8 most significant bits (MSB) of a given axis int read_axis_data_8_bits(Axis axis); private: I2C device; const int slave_address; }; #endif