summaryrefslogtreecommitdiff
path: root/ak8975.h
blob: beb9940ad36a80672bbe7a830daa80ab67bce8c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#ifndef AK8975_H
#define AK8975_H

#include "i2csensor.h"

class AK8975 : public I2CSensor {
	public:
		int16_t x, y, z;
		
		void init() {
			i2c_address = 0x0c;
			write(0x0a, 0x01); // Start first measurement.
		}
		
		void update() {
			read(0x03, 6);
			x = (rxdata[0] | rxdata[1] << 8);
			y = (rxdata[2] | rxdata[3] << 8);
			z = (rxdata[4] | rxdata[5] << 8);
			write(0x0a, 0x01); // Start a new measurement.
		}
};

#endif