|
Last change
on this file since 19862 was 17969, checked in by dneise, 12 years ago |
|
adding libraries folder, with LSM303 lib, this takes precedence over any locally installed LSM303 library, e.g. in HOME/arduino-1.0.6/libraries.
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | #include <Wire.h>
|
|---|
| 2 | #include <LSM303.h>
|
|---|
| 3 |
|
|---|
| 4 | LSM303 compass;
|
|---|
| 5 |
|
|---|
| 6 | void setup() {
|
|---|
| 7 | Serial.begin(9600);
|
|---|
| 8 | Wire.begin();
|
|---|
| 9 | compass.init();
|
|---|
| 10 | compass.enableDefault();
|
|---|
| 11 |
|
|---|
| 12 | /*
|
|---|
| 13 | Calibration values; the default values of +/-32767 for each axis
|
|---|
| 14 | lead to an assumed magnetometer bias of 0. Use the Calibrate example
|
|---|
| 15 | program to determine appropriate values for your particular unit.
|
|---|
| 16 | */
|
|---|
| 17 | compass.m_min = (LSM303::vector<int16_t>){-32767, -32767, -32767};
|
|---|
| 18 | compass.m_max = (LSM303::vector<int16_t>){+32767, +32767, +32767};
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | void loop() {
|
|---|
| 22 | compass.read();
|
|---|
| 23 |
|
|---|
| 24 | /*
|
|---|
| 25 | When given no arguments, the heading() function returns the angular
|
|---|
| 26 | difference in the horizontal plane between a default vector and
|
|---|
| 27 | north, in degrees.
|
|---|
| 28 |
|
|---|
| 29 | The default vector is chosen by the library to point along the
|
|---|
| 30 | surface of the PCB, in the direction of the top of the text on the
|
|---|
| 31 | silkscreen. This is the +X axis on the Pololu LSM303D carrier and
|
|---|
| 32 | the -Y axis on the Pololu LSM303DLHC, LSM303DLM, and LSM303DLH
|
|---|
| 33 | carriers.
|
|---|
| 34 |
|
|---|
| 35 | To use a different vector as a reference, use the version of heading()
|
|---|
| 36 | that takes a vector argument; for example, use
|
|---|
| 37 |
|
|---|
| 38 | compass.heading((LSM303::vector<int>){0, 0, 1});
|
|---|
| 39 |
|
|---|
| 40 | to use the +Z axis as a reference.
|
|---|
| 41 | */
|
|---|
| 42 | float heading = compass.heading();
|
|---|
| 43 |
|
|---|
| 44 | Serial.println(heading);
|
|---|
| 45 | delay(100);
|
|---|
| 46 | } |
|---|
Note:
See
TracBrowser
for help on using the repository browser.