summaryrefslogtreecommitdiff
path: root/itg3200.h
blob: 90cc4b3bae80a9dd080632f58a4b89bdcd581b1a (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 ITG3200_H
#define ITG3200_H

#include "i2csensor.h"

class ITG3200 : public I2CSensor {
	public:
		int16_t x, y, z;
		
		void init() {
			i2c_address = 0x68;
			write(0x3e, 0x03); // Select clock reference.
			write(0x16, 0x18 | 0x02); // 2000 deg/sec range, 98 Hz bandwidth.
		}
		
		void update() {
			read(0x1d, 6);
			x = (rxdata[0] << 8 | rxdata[1]) - -50;
			y = (rxdata[2] << 8 | rxdata[3]) - 36;
			z = (rxdata[4] << 8 | rxdata[5]) - 2;
		}
};

#endif