OK we managed but still cannot test.
This places the check on ATOsolenoid into the switch/case logic:
// start or continue hourly 20 second flushing
switch (state) {
case Idle : // start flsushing
if (digitalRead(ATOsolenoid) == HIGH) {
state = Flush;
msec0 = msec;
digitalWrite(FlushSolenoid, HIGH); //Switch Solenoid ON
}
break;
case Flush : // flush for 20 seconds
if (msec - msec0 >= MsecFlush) {
msec0 = msec;
state = Waiting;
digitalWrite(FlushSolenoid, LOW); //Switch Solenoid ON
}
break;
case Waiting : // wait an hour, or reset the flushing machine if ATOsolenoid says
if (msec - msec0 >= MsecIdle) {
msec0 = msec;
state = Flush;
digitalWrite(FlushSolenoid, LOW); //Switch Solenoid OFF (time to)
}
else if (digitalRead(ATOsolenoid) == LOW) {
state = Idle;
digitalWrite(FlushSolenoid, LOW); //Switch Solenoid OFF (ATOsolenoid dropped)
}
break;
}
}
We added a state, just add it to the enum that holds the other states. So it is Idle, Flushing or Waiting out an hour for the next flush.
enum {Idle, Flush, Waiting};
int state = Idle;
Which now I see that second machine is like @noiasca's, except it uses the solenoid state rather than the sensors for deciding to, or not to, flush and wait repeatedly.
a7