@ScruffR worked perfectly, thank you. I now have this code which works well:
void goIntoLowPowerMode()
{
int sleepLeft = SLEEP_PERIOD;
int startSleep = Time.now();
while (sleepLeft > 0) {
int rainCounterBeforeSleep = rainCounter;
System.sleep(RAIN_PIN, FALLING, sleepLeft );
sleepLeft = SLEEP_PERIOD - (Time.now() - startSleep);
if (sleepLeft > 0) {
// RAIN_PIN was tripped because there is time left on the timer
// Wake just long enough to count the pulse, then go back to sleep for remaining time
unsigned long timeout = millis();
while (rainCounterBeforeSleep == rainCounter && millis() - timeout < 10) delay(1);
}
}
}
If the pin falls and causes System.sleep
to return, do you know if the ISR also attached to the falling edge of that pin will get called immediately so I can count the pulse, before I get around the loop and back into the sleep? Or is that indeterminate? I’m just wondering if that code I have above waiting for the count to increment is necessary.