interrupt delay with RTC?

I lifted this fade sketch from tutorials and played around with it to have a period of full intensity and a period of darkness. The fade is easy to stretch with the dimming delay.

Is it feasible to make the darkness delay (last line in sketch) say, 20 hours, but before 20 hours is up, start the sketch at the beginning using an RTC?

What I have in mind is to use this for sunrise/sunset on my aquarium. The RTC would start the sketch at 9:00 AM and I'd use a 12 hour delay for lights on. Then the 20 hour darkness delay would get interrupted at 9:00 AM by the RTC to start things over again.

Is that doable?


[code
int ledPin = 9;    // LED connected to digital pin 9

void setup() {
  // nothing happens in setup
}

void loop() {

   
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 0 to 255):
    analogWrite(purpLED, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);
  }
delay(19000); //light delay, 19 seconds of full intensity
  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    // sets the value (range from 0 to 255):
    analogWrite(purpLED, fadeValue);
    // wait for 30 milliseconds to see the dimming effect
    delay(30);}
  
    
 delay(19000); // darkness delay, 19 seconds of darkness
}]

Also ... please don't use code tags.

I mean for code, yeah - you're supposed to use them. But not for text - too much horizontal scrolling!

The demo Several Things at a Time is an extended example of BWoD and illustrates the use of millis() to manage timing. It may help with understanding the technique.

If you don't use delay() there will be no need to interrupt it.

...R

OK, thanks guys.

As for the code tags, I got all kinds of grief awhile ago for using 'magic numbers'.