2013-09-30 11:03:06 -04:00
|
|
|
//
|
|
|
|
// FILE: standbyDemo.pde
|
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// VERSION: 0.1.00
|
|
|
|
// PURPOSE: demo app HMC6352 library - standby mode for Arduino
|
|
|
|
//
|
|
|
|
// HISTORY:
|
|
|
|
// 0.1.00 - 2011-04-12 initial version
|
|
|
|
//
|
|
|
|
// Released to the public domain
|
|
|
|
//
|
|
|
|
// All disclaimers apply use at own risk
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <Wire.h>
|
|
|
|
#include <hmc6352.h>
|
|
|
|
|
|
|
|
hmc6352 Compass(0x21); // 0x21 <==> 33 <==> 66 >> 1
|
|
|
|
|
|
|
|
void setup()
|
|
|
|
{
|
|
|
|
Serial.begin(19200);
|
|
|
|
Serial.println("HMC6352: Version ");
|
|
|
|
Serial.println(HMC_LIB_VERSION);
|
|
|
|
Serial.print("current output modus");
|
|
|
|
Serial.println(Compass.getOutputModus());
|
|
|
|
}
|
|
|
|
int x;
|
|
|
|
|
|
|
|
void loop()
|
|
|
|
{
|
2013-09-30 11:09:58 -04:00
|
|
|
Compass.wakeUp(); // decent wake up from sleep mode
|
2013-09-30 11:03:06 -04:00
|
|
|
|
|
|
|
// Note that reading a heading is requires two steps, ask() & read()
|
|
|
|
// this makes the query and continuous mode more efficient
|
|
|
|
// without impact on the footprint of the lib.
|
2013-09-30 11:09:58 -04:00
|
|
|
// this way one can ask a make a reading and fetch it a bit later.
|
|
|
|
// TODO is it fast enough for IRQ ?
|
2013-09-30 11:03:06 -04:00
|
|
|
x = Compass.askHeading();
|
|
|
|
//Serial.print("Ask returns: ");
|
|
|
|
//Serial.println(x);
|
|
|
|
|
|
|
|
x = Compass.readHeading();
|
2013-09-30 11:09:58 -04:00
|
|
|
Serial.print("ask & read : Degree : ");
|
2013-09-30 11:03:06 -04:00
|
|
|
Serial.println(x);
|
|
|
|
|
|
|
|
Compass.sleep(); // low energy mode
|
|
|
|
delay(500);
|
2013-09-30 11:09:58 -04:00
|
|
|
|
|
|
|
// this is the simplest mode to use the library
|
|
|
|
// suitable for 99.9% of all robots :)
|
|
|
|
Compass.wakeUp();
|
|
|
|
Serial.print("getHeading : Degree : ");
|
|
|
|
Serial.println(Compass.getHeading());
|
|
|
|
Compass.sleep();
|
|
|
|
delay(500);
|
2013-09-30 11:03:06 -04:00
|
|
|
}
|
|
|
|
// END OF FILE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|