source: rtos_arduino/trunk/arduino_lib/libraries/Robot_Control/src/Compass.cpp@ 136

Last change on this file since 136 was 136, checked in by ertl-honda, 8 years ago

ライブラリとOS及びベーシックなサンプルの追加.

File size: 869 bytes
Line 
1#include "Compass.h"
2#include <Wire.h>
3
4void Compass::begin(){
5 Wire.begin();
6}
7float Compass::getReading(){
8 _beginTransmission();
9 _endTransmission();
10
11 //time delays required by HMC6352 upon receipt of the command
12 //Get Data. Compensate and Calculate New Heading : 6ms
13 delay(6);
14
15 Wire.requestFrom(HMC6352SlaveAddress, 2); //get the two data bytes, MSB and LSB
16
17 //"The heading output data will be the value in tenths of degrees
18 //from zero to 3599 and provided in binary format over the two bytes."
19 byte MSB = Wire.read();
20 byte LSB = Wire.read();
21
22 float headingSum = (MSB << 8) + LSB; //(MSB / LSB sum)
23 float headingInt = headingSum / 10;
24
25 return headingInt;
26}
27
28void Compass::_beginTransmission(){
29 Wire.beginTransmission(HMC6352SlaveAddress);
30 Wire.write(HMC6352ReadAddress);
31}
32void Compass::_endTransmission(){
33 Wire.endTransmission();
34}
Note: See TracBrowser for help on using the repository browser.