I intend to make the device runs about couple hours a day(let say 2hrs) -> go to deep sleep -> wake up in next 7 days -> repeat the process.
I got the code from one of member here (DotPi) which I can able to make the device wake up every 10 seconds and then back to sleep. When it wakes up, the LED is flashing.
My question is how to make the LED flashes for certain amount of time. For example from 7pm to 8 pm. After that the device should go to sleep again and wait for the next alarm triggered.
I was trying to use the while loop for that but the LED always flash and never go back to sleep :(
-
You are setting the alarm every iteration of your loop. You want to put that in your setup() function.PhillyNJ– PhillyNJ2017年07月29日 20:26:11 +00:00Commented Jul 29, 2017 at 20:26
-
even I put the "rtc.setAlarm" function in main loop, the device still repeat every 10 second as I expect. My problem is I want to flash the LED for certain amount of time (as the while loop) but the LED is always flashing and never get out of that while loop even the current minute is greater than 30.no0b31– no0b312017年07月30日 00:25:45 +00:00Commented Jul 30, 2017 at 0:25
-
1Also asked at: forum.arduino.cc/index.php?topic=492180per1234– per12342017年07月30日 01:26:18 +00:00Commented Jul 30, 2017 at 1:26
1 Answer 1
In your while loop, you never check the time again, so when the while loops hits, you will never leave it. You need to request the time again. Something like:
while ( now.minute()>0 && now.minute() < 30)
{
digitalWrite(ledPin, HIGH);
delay(100);
digitalWrite(ledPin, LOW);
delay(1000);
now = rtc.now(); // check time again
}
-
cool, I got what u mean. Silly me :Dno0b31– no0b312017年07月30日 02:26:01 +00:00Commented Jul 30, 2017 at 2:26