2017-09-13 02:58:18 -04:00
|
|
|
//
|
|
|
|
// FILE: queryDemo.ino
|
2013-09-30 11:03:06 -04:00
|
|
|
// AUTHOR: Rob Tillaart
|
2020-11-27 05:16:22 -05:00
|
|
|
// PURPOSE: demo HMC6352 library - query mode for Arduino
|
2021-12-19 07:57:35 -05:00
|
|
|
|
2013-09-30 11:03:06 -04:00
|
|
|
|
|
|
|
#include <hmc6352.h>
|
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
hmc6352 Compass(0x21);
|
|
|
|
|
|
|
|
int heading;
|
2013-09-30 11:03:06 -04:00
|
|
|
|
2021-12-19 07:57:35 -05:00
|
|
|
|
2013-09-30 11:03:06 -04:00
|
|
|
void setup()
|
|
|
|
{
|
2020-11-27 05:16:22 -05:00
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
|
|
|
Serial.println("LIB: ");
|
|
|
|
Serial.println(HMC6352_LIB_VERSION);
|
|
|
|
|
|
|
|
Compass.begin();
|
2021-12-19 07:57:35 -05:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
Serial.print("Output modus: ");
|
2013-09-30 11:03:06 -04:00
|
|
|
Serial.println(Compass.getOutputModus());
|
2017-09-13 02:58:18 -04:00
|
|
|
|
2020-11-27 05:16:22 -05:00
|
|
|
heading = Compass.askHeading();
|
|
|
|
Serial.print("Ask returns: ");
|
|
|
|
Serial.println(heading);
|
2013-09-30 11:03:06 -04:00
|
|
|
}
|
|
|
|
|
2021-12-19 07:57:35 -05:00
|
|
|
|
2013-09-30 11:03:06 -04:00
|
|
|
void loop()
|
|
|
|
{
|
|
|
|
// in query mode it is not needed to ask for a new reading every time
|
|
|
|
// as it will do a new reading directly after the chip is read
|
|
|
|
// and waits until it is asked for.
|
|
|
|
// Try making a fast turn and smile ...
|
2020-11-27 05:16:22 -05:00
|
|
|
heading = Compass.readHeading();
|
2013-09-30 11:03:06 -04:00
|
|
|
Serial.print("Degree : ");
|
2020-11-27 05:16:22 -05:00
|
|
|
Serial.println(heading);
|
2013-09-30 11:03:06 -04:00
|
|
|
delay(1000);
|
|
|
|
}
|
|
|
|
|
2021-12-19 07:57:35 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|