Open
Description
This simple sketch (on a SAMD21, for ex. MKR WiFi 1010):
#include <ArduinoLowPower.h>
void setup()
{
pinMode(0, OUTPUT);
digitalWrite(0, LOW);
}
void loop()
{
LowPower.idle();
digitalWrite(0, !digitalRead(0));
}
produces a nice ~500 Hz square wave on pin D0, because the IDLE state is ended by the SysTick interrupt every ms.
This is fine and useful, but should be properly documented.
Adding any value as argument to LowPower.idle(): (I use random()
here to emphasize any)
LowPower.idle((int)random(1000));
lowers the frequency to ~10.6 Hz.
Setting the RTC alarm takes ~46 ms, and then the IDLE state is ended on the next SysTick interrupt.
Most of the time needed to set the RTC alarm comes from synchronisation calls in RTCZero.cpp
like
while (RTCisSyncing())
;
I guess looping around the wfi
instruction waiting for the right time to pass would be a better solution than using the RTC...