const byte out1 = 10;
const byte in1 = 2;
const byte in2 = 3;
const byte in3 = 4;
const byte in4 = 5;
const unsigned long actionDelay = 2500; // allowable time for flow to be distrupted without stoppage
void setup() {
pinMode(out1, OUTPUT);
digitalWrite(out1, HIGH);
pinMode(in1, INPUT_PULLUP);
pinMode(in2, INPUT_PULLUP);
pinMode(in3, INPUT_PULLUP);
pinMode(in4, INPUT_PULLUP);
delay(5000);
}
void loop() {
static unsigned long readTime; // time at action
unsigned long now = millis();
bool flowIsLow1= digitalRead(in1) == HIGH;
bool flowIsLow2= digitalRead(in2) == HIGH;
bool flowIsLow3= digitalRead(in3) == HIGH;
bool flowIsLow4= digitalRead(in4) == HIGH;
bool pumpFault = flowIsLow1 || flowIsLow2 || flowIsLow3 || flowIsLow4;
// if flow is good and flow switches are closed
if (!pumpFault) {
readTime = now;
digitalWrite(out1, HIGH);
}
// when (if!) the timer expires, turn ON the LED
if (now - readTime >= actionDelay) {
digitalWrite(out1, LOW);
}
}