11 #ifndef __MMA8452_HEADER
12 #define __MMA8452_HEADER
40 #define XYZ_DATA_CFG 0x0E
42 #define CTRL_REG1 0x2A
44 #ifndef MMA8452_ADDRESS
45 #define MMA8452_ADDRESS 0x1D // 0x1D if SA0 is high, 0x1C if low
50 void init(uint8_t
const & g_scale = 2) {
54 ASSERT_MSG(c == 0x2A,
"Couldn't connect to MMA8452")
93 for(
int i = 0;
i < 3 ;
i++) {
94 int g_count = (raw_data[
i*2] << 8) | raw_data[(
i*2)+1];
98 if (raw_data[
i*2] > 0x7F) {
99 g_count = ~g_count + 1;
103 accel[
i] = double(g_count) / ((1<<12)/(2*g_scale_));
111 double const &
x()
const {
114 double const &
y()
const {
117 double const &
z()
const {
127 #endif //__MMA8452_HEADER
void standby()
Definition: MMA8452.hpp:68
#define CTRL_REG1
Definition: MMA8452.hpp:42
#define XYZ_DATA_CFG
Definition: MMA8452.hpp:40
void init(uint8_t const &g_scale=2)
Definition: MMA8452.hpp:50
class com::i2cout_class i2cout
#define ASSERT_MSG(exp, msg)
Definition: ard_assert.hpp:34
double const & x() const
Definition: MMA8452.hpp:111
double const & y() const
Definition: MMA8452.hpp:114
void active()
Definition: MMA8452.hpp:72
struct ustd::endl_class endl
void update()
Definition: MMA8452.hpp:88
uint8_t const OUT_X_MSB
Definition: MMA8452.hpp:39
void write_register(byte address, byte data)
Definition: MMA8452.hpp:84
#define WHO_AM_I
Definition: MMA8452.hpp:41
#define MMA8452_ADDRESS
Definition: MMA8452.hpp:45
double const & z() const
Definition: MMA8452.hpp:117
double const & operator[](uint8_t const &idx) const
Definition: MMA8452.hpp:107
#define ASSERT(exp)
Definition: ard_assert.hpp:33
Definition: MMA8452.hpp:47
uint8_t read_register(byte address)
Definition: MMA8452.hpp:77
class com::i2cin_class i2cin