Thanks everyone for the helpful info so far. As for the logic behind the code I would like the FlushSolenoid's 20 second occurrence to turn on given two conditions: 1) Anytime the ATOsolenoid is HIGH (turned on) or 2) anytime the ATOsolenoid has been running for more than 1 hour. For some background this FlushSolenoid will be used to start a black-flush in the system and ideally will run its 20 second cycle anytime the main ATOsolenoid starts and then once every hour when the ATOsolenoid is on. Here is what I have attempted for the code regarding this operation:
#define EXE_INTERVAL_1 5000
#define EXE_INTERVAL_2 10000
void Loop()
//Flush Solenoid
unsigned long lastExecutedMillis_1 = 0; // vairable to save the last executed time for code block 1
unsigned long lastExecutedMillis_2 = 0; // vairable to save the last executed time for code block 2
unsigned long currentMillis = millis();
if (digitalRead(ATOsolenoid == HIGH)) {
digitalWrite(FlushSolenoid, HIGH);
}
if (currentMillis - lastExecutedMillis_1 >= EXE_INTERVAL_1) {
lastExecutedMillis_1 = currentMillis; // save the last executed time
digitalWrite(FlushSolenoid, HIGH);
}
if (currentMillis - lastExecutedMillis_2 >= EXE_INTERVAL_2) {
lastExecutedMillis_2 = currentMillis; // save the last executed time
digitalWrite(FlushSolenoid, LOW);
}
}
The flush solenoid does turn on for 10 seconds when executing the code, but does not reset back to on (HIGH) when I trigger the ATOSolenoid to turn on by manipulating the eyes. It also does not seem to reset/loop every 5 seconds as I thought it would (just using 5 seconds as a test interval - this will ultimately be the 1 hour when I get the code operational). Thanks again