GY-63_MS5611/libraries/hmc6352/examples/standbyDemo/standbyDemo.ino

62 lines
1.2 KiB
Arduino
Raw Normal View History

//
// FILE: standbyDemo.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo app HMC6352 library - standby mode for Arduino
2021-06-07 12:21:42 -04:00
#include <hmc6352.h>
2020-11-27 05:16:22 -05:00
hmc6352 Compass(0x21);
2021-06-07 12:21:42 -04:00
2020-11-27 05:16:22 -05:00
int heading;
void setup()
{
2020-11-27 05:16:22 -05:00
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println("LIB: ");
Serial.println(HMC6352_LIB_VERSION);
2021-06-07 12:21:42 -04:00
Wire.begin();
2020-11-27 05:16:22 -05:00
Compass.begin();
2021-12-19 07:57:35 -05:00
2020-11-27 05:16:22 -05:00
Serial.print("Output modus");
Serial.println(Compass.getOutputModus());
}
2021-06-07 12:21:42 -04:00
void loop()
{
2013-09-30 11:09:58 -04:00
Compass.wakeUp(); // decent wake up from sleep mode
// 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 ?
2020-11-27 05:16:22 -05:00
int x = Compass.askHeading();
2021-06-07 12:21:42 -04:00
Serial.print("Ask returns: ");
Serial.print(x);
2020-11-27 05:16:22 -05:00
heading = Compass.readHeading();
2021-06-07 12:21:42 -04:00
Serial.print("\task & read : ");
2020-11-27 05:16:22 -05:00
Serial.println(heading);
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();
2020-11-27 05:16:22 -05:00
Serial.print("getHeading : ");
2013-09-30 11:09:58 -04:00
Serial.println(Compass.getHeading());
Compass.sleep();
2021-06-07 12:21:42 -04:00
2013-09-30 11:09:58 -04:00
delay(500);
}
2021-12-19 07:57:35 -05:00
2021-06-07 12:21:42 -04:00
// -- END OF FILE --
2021-12-19 07:57:35 -05:00