Вт мар 08, 2022 17:44:27
Чт мар 10, 2022 01:45:04
void loop() {
int x,y,z;
compass.read(&x,&y,&z);
// Calculate heading when the magnetometer is level, then correct for signs of axis.
// Atan2() automatically check the correct formula taking care of the quadrant you are in
float heading = atan2(y, x);
float declinationAngle = 0.0404;
heading += declinationAngle;
// Find yours here: http://www.magnetic-declination.com/
// Correct for when signs are reversed.
if(heading < 0)
heading += 2*PI;
// Check for wrap due to addition of declination.
if(heading > 2*PI)
heading -= 2*PI;
// Convert radians to degrees for readability.
float headingDegrees = heading * 180/M_PI;
delay(100);
}