-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMPS10.h
More file actions
54 lines (47 loc) · 1.24 KB
/
CMPS10.h
File metadata and controls
54 lines (47 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/*
* CMPS10.h - Library for easy use of the CMPS10 tilt-compensating digital
* compass.
*
* https://github.com/kragniz/CMPS10
*
* Copyright (C) 2013 Louis Taylor <kragniz@gmail.com>
*
* This code is released under the terms of the LGPLv3 licence.
*/
#ifndef CMPS10_h
#define CMPS10_h
#include "Arduino.h"
// I2C registers
#define COMPASS_BEARING 1
#define COMPASS_DECIMAL_HIGH 2
#define COMPASS_DECIMAL_LOW 3
#define COMPASS_PITCH 4
#define COMPASS_ROLL 5
// accelerometer registers
#define ACCEL_X_HIGH 16
#define ACCEL_X_LOW 17
#define ACCEL_Y_HIGH 18
#define ACCEL_Y_LOW 19
#define ACCEL_Z_HIGH 20
#define ACCEL_Z_LOW 21
class CMPS10 {
public:
CMPS10();
CMPS10(int i2c_address);
int bearing_byte();
float bearing();
int8_t pitch();
int8_t roll();
float acceleration();
float acceleration_x();
float acceleration_y();
float acceleration_z();
private:
int compass_address;
byte read_i2c(int address, int _register);
float read_word(int high_address, int low_address);
int16_t read_int16_t(int high_address, int low_address);
void init(int i2c_address);
float raw_to_g(int16_t raw);
};
#endif