Created
August 4, 2017 15:18
-
-
Save ShawnHymel/eacf471de375e188d69140ba90f313da to your computer and use it in GitHub Desktop.
Digital Compass
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Digital Compass | |
* MAG3110 Demo | |
* | |
* Author: Shawn Hymel (SparkFun Electronics) | |
* Based on SparkFun_MAG3110_Calibrated.ino by George B. | |
* Date: July 25, 2017 | |
* | |
* Connect MAG3110 to MicroView. If "Calibrating" appears, | |
* slowly rotate the MAG3110 sensor 360 degrees while flat on | |
* a surface (i.e. Z axis is pointing up or down). | |
* | |
* After, a heading will appear: | |
* 0 deg = North | |
* 90 deg = Easth | |
* 180/-180 deg = South | |
* -90 deg = West | |
* | |
* This code is beerware; if you see me (or any other SparkFun | |
* employee) at the local, and you've found our code helpful, | |
* please buy us a round! | |
* Distributed as-is; no warranty is given. | |
*/ | |
#include <MicroView.h> | |
#include <SparkFun_MAG3110.h> | |
MAG3110 mag = MAG3110(); | |
void setup() { | |
uView.begin(); | |
uView.clear(ALL); | |
uView.display(); | |
mag.initialize(); | |
} | |
void loop() { | |
// Clear display | |
uView.clear(PAGE); | |
uView.setCursor(0, 0); | |
// If we are calibrated, display heading | |
if ( mag.isCalibrated() ) { | |
uView.setFontType(1); | |
uView.print(mag.readHeading()); | |
delay(100); | |
} else { | |
// Tell user we are calibrating | |
uView.setFontType(0); | |
uView.println("Calibratin"); | |
uView.print("Rotate me!"); | |
// Calibrate or enter into calibration mode | |
if ( mag.isCalibrating() ) { | |
mag.calibrate(); | |
} else { | |
mag.enterCalMode(); | |
} | |
delay(10); | |
} | |
// Draw! | |
uView.display(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment