Skip to content

Commit

Permalink
Add magHorizlDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
asukiaaa committed Aug 10, 2017
1 parent 4a20065 commit 084b512
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/GetData/GetData.ino
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ void loop() {
Serial.println("magX: " + String(mySensor.magX()));
Serial.println("maxY: " + String(mySensor.magY()));
Serial.println("magZ: " + String(mySensor.magZ()));
Serial.println("horizontal direction: " + String(mySensor.magHorizDirection()));

Serial.println("at " + String(millis()) + "ms");
delay(500);
Expand Down
6 changes: 6 additions & 0 deletions src/MPU9250_asukiaaa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ void MPU9250::magSetMode(uint8_t mode) {
delay(10);
}

const float Pi = 3.14159;

float MPU9250::magHorizDirection() {
return atan2((float) magX(), (float) magY()) * 180 / Pi;
}

void MPU9250::magUpdate() {
I2Cread(MAG_ADDRESS, AK8963_RA_HXL, 7, magBuf);
}
Expand Down
2 changes: 2 additions & 0 deletions src/MPU9250_asukiaaa.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define MPU9250_ASUKIAAA
#include <Arduino.h>
#include <Wire.h>
#include <math.h>

#define MPU9250_ADDRESS_AD0_LOW 0x68
#define MPU9250_ADDRESS_AD0_HIGH 0x69
Expand Down Expand Up @@ -53,6 +54,7 @@ class MPU9250 {
int16_t magY();
int16_t magZ();
void magSetMode(uint8_t mode);
float magHorizDirection();

private:
TwoWire* myWire;
Expand Down

0 comments on commit 084b512

Please sign in to comment.