0

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 Jul 29 '17 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 Jul 30 '17 at 0:25
  • 1
    Also asked at: forum.arduino.cc/index.php?topic=492180 – per1234 Jul 30 '17 at 1:26
0

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 :D – no0b31 Jul 30 '17 at 2:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.