df

Dependencies:   mbed

Fork of APP1 by Team APP

Accelerometer.hpp

Committer:
dupm2216
Date:
2017-01-14
Revision:
1:7becb0e903e3
Child:
3:1a9d0f0a50bf

File content as of revision 1:7becb0e903e3:

#include <memory>

#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;

class Accelerometer
{
    public:
        Accelerometer(I2C& device, const int slave_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 6 bytes
        void read_all_axis(char* axis_data);
        void print_all_axis_data();
        
        void set_standby();
        void set_active();
        void init();
    
    private:
        I2C& device;
        const int slave_address;
};