Tony YI
/
ESDC2014
123123123123123123123123123
Diff: compass.h
- Revision:
- 0:3417ca0a36c0
- Child:
- 1:cbec1283a16a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/compass.h Tue Jul 01 10:59:33 2014 +0000 @@ -0,0 +1,54 @@ +#ifndef HMC5883L_H +#define HMC5883L_H + +#include "mbed.h" + +#define HMC5883L_IDENT_A 0x0A // In this case the identification register A is used to identify the devide. ASCII value H +#define HMC5883L_I2C 0x1E // 7-bit address. 0x3C write, 0x3D read. +#define HMC5883L_I2C_WRITE 0x3C // Same as (& 0xFE), ensure that the MSB bit is being set to zero (RW=0 -> Writing) +#define HMC5883L_I2C_READ 0x3D // Same as (| 0x01), ensure that the MSB bit is being set to one (RW=1 -> Reading) + +#define HMC5883L_CONFIG_A 0x00 +#define HMC5883L_CONFIG_B 0x01 +#define HMC5883L_MODE 0x02 +#define HMC5883L_STATUS 0x09 + +#define HMC5883L_X_MSB 0x03 +#define HMC5883L_X_LSB 0x04 +#define HMC5883L_Z_MSB 0x05 +#define HMC5883L_Z_LSB 0x06 +#define HMC5883L_Y_MSB 0x07 +#define HMC5883L_Y_LSB 0x08 +#define PI 3.14159265 +#define SDA p9 +#define SCL p10 + +#define DECLINATIONANGLE -0.0457 +#define OFFSET 0 + +#include <math.h> + +class HMC5883L +{ + +public: + + HMC5883L(PinName sda, PinName scl); + float getMx(); + float getMy(); + float getMz(); + + void setDeclination(float declinationAngle); + void setOffset(int offset); + + unsigned short get_degree(); +private: + void Write(char reg_address, char data); + char Read(char data); + void MultiByteRead(char address, char* output, int size); + I2C i2c; + float declinationAngle; + int offset; +}; + +#endif /* HMC5883L_H */ \ No newline at end of file