Something basic like this would work, flesh out the definitions, pin assignments, other stuff.
Basically, you push the start button at 8:30.
It reads the current value of millis, then sits in a loop reading millis and comparing to the initial read until 8.5 hrs have gone by for interval1.
It then sets some flags and sits in the loop again until 15.5 hrs have gone by for interval2.
Then it repeats.
unsigned long currentmillis = 0; // value from 0 to 4294967295 (hex FFFF FFFF, a 32 bit number)
unsigned long elapsedmillis = 0;
unsigned long previousmillis = 0;
//unsigned long interval1 = 3060000; // = 8.5hrs x 60 min/hr * 60 sec/min * 1000ms/sec
//unsigned long interval2 = 55800000; // = (24-8.5)hrs x 60 min/hr * 60 sec/min * 1000ms/sec
unsigned long interval1 = 5000; // for testing, replace with above
unsigned long interval2 = 5000; // for testing, replace with above
byte interval1_active = 0; // flag =1 to show interval1 in process
byte interval2_active = 0; // flag =1 to show interval2 in process
byte start_button = 2; // pin2 for start button
byte start_button_state = 1; // state of the active low (connect to ground) button
void setup(){
Serial.begin (9600);
pinMode (start_button, INPUT);
digitalWrite (start_button, HIGH); // internal pullup turned on
}
void loop()
{
start_button_state = digitalRead (start_button); // read the active low (internal pullup) start button
if (start_button_state == 0 && interval1_active == 0) // uses interval1 to ignore switch bounce once pushed
{ // once pressed,
Serial.println ("Started!"); // let the user know
interval1_active = 1; // and set a flag for interval1
currentmillis = millis(); // take a snapshot of current time
previousmillis = currentmillis; // sets difference to 0
}
if (interval1_active == 0 && interval2_active == 0) // nothing going on yet
{
Serial.println ("Waiting for 8:30"); // let user know waiting for start time
delay (1000); // but not too often
}
if (interval1_active == 1 && interval2_active == 0){
currentmillis = millis(); // read the time.
elapsedmillis = currentmillis - previousmillis; // compute how much has gone by
if (elapsedmillis >= interval1) // 8.5 hrs have gone by
{
Serial.println ("8.5 hrs elapsed");
interval1_active = 0; // turn off 1st flag
interval2_active = 1; // turn on 2nd
previousmillis = currentmillis; // reset the difference to 0
elapsedmillis = 0;
}
}
if (interval1_active == 0 & interval2_active == 1){
currentmillis = millis(); // read the time.
elapsedmillis = currentmillis - previousmillis; // compute how much has gone by
if (elapsedmillis >= interval2) // (24-8.5) hrs have gone by
{
Serial.println ("15.5 hrs elapsed");
interval1_active = 1;
interval2_active = 0;
previousmillis = currentmillis;
elapsedmillis = 0;
}
}
} // end void looop