Lab_interaccio/2016/SMARTCITIZEN_15/LSM303/Heading/Heading.ino
2025-02-25 21:29:42 +01:00

49 lines
1.3 KiB
C++

#include <Wire.h>
#include "LSM303.h"
LSM303 compass;
void setup() {
Serial.begin(9600);
Wire.begin();
compass.init();
compass.enableDefault();
/*
Calibration values; the default values of +/-32767 for each axis
lead to an assumed magnetometer bias of 0. Use the Calibrate example
program to determine appropriate values for your particular unit.
*/
compass.m_min = (LSM303::vector<int16_t>){-3305, -1552, -2705};
compass.m_max = (LSM303::vector<int16_t>){+3370, +2796, +2058};
}
void loop() {
compass.read();
/*
When given no arguments, the heading() function returns the angular
difference in the horizontal plane between a default vector and
north, in degrees.
The default vector is chosen by the library to point along the
surface of the PCB, in the direction of the top of the text on the
silkscreen. This is the +X axis on the Pololu LSM303D carrier and
the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH
carriers.
To use a different vector as a reference, use the version of heading()
that takes a vector argument; for example, use
compass.heading((LSM303::vector<int>){0, 0, 1});
to use the +Z axis as a reference.
*/
float heading = compass.heading();
Serial.println(heading);
delay(100);
}