Hi Gypsum, Thank you very much! sometimes people need a break to keep the concentration and refresh the objectivity.
The trouble continues with my sketch, now the relays (2, 3, 4) run before the previous one (relay 1) finishes with the if statement (value1 >= maxVal). Additionally, the snnipets "delay(elapsed)" stop the loop,producing the increment of the elapsed time .
Any suggestions will be well received.
Thank you all
Regards
// turn the Relay1 on
if (value1>= maxVal){
digitalWrite(Relay1, LOW);}
if (value1<= minVal){
digitalWrite(Relay1, HIGH);}
if(digitalRead(Relay1) == LOW){
//turn on millis
start=millis();
delay(10); // for debounce
Serial.println("Started...");}
if (digitalRead (Relay1) == HIGH)
{
time = millis();
finished = millis();
elapsed = finished - start;
displayResult();
delay (10);
}
if (value1<=maxVal){
//turn on relay 2 during millis period
if (Relay1State == LOW && Relay3State == LOW && Relay4State == LOW && previous == LOW && millis()- time > debounce)
{
digitalWrite(Relay2, HIGH);
delay(elapsed);
digitalWrite(Relay2, LOW);
delay (20);
}
//turn on relay 3 during millis period
if (Relay1State == LOW && Relay2State == LOW && Relay4State == LOW && previous == LOW && millis()- time > debounce)
{
digitalWrite(Relay3, HIGH);
delay(elapsed);
digitalWrite (Relay3, LOW);
}
delay (20);
//turn on relay 2 during millis period
if (Relay1State == LOW && Relay2State == LOW && Relay3State == LOW && previous == LOW && millis()- time > debounce)
{
digitalWrite(Relay4, HIGH);
delay (elapsed);
digitalWrite (Relay4, LOW);
}
delay (20);
}
Series2_Rx.ino (4.98 KB)