Hi,
I'm trying to control four relays with a signal from one sensor. The signal comes from a remote sensor. The relay's operation time base is fixed by the elapsed time of the operation from the first relay, the following relays operate with this calculated elapsed time.
My skech runs fine until the value of the signal is received, after that moment the loop doesn't nothing. Only receives constantly the value but doesn't calculate the elapsed time neither the relays operate.
I appreciate very much to anyone who help me.
Regards
// I check both bytes (or)
uint8_t analogMSB = rx.getData(0);
uint8_t analogLSB = rx.getData(1);
value1 = analogLSB + (analogMSB * 256);
Serial.print("V from Sensor 1= ");
Serial.println(value1);
// // I check both bytes (or)
// uint8_t analogMSB1 = rx.getData(2);
// uint8_t analogLSB1 = rx.getData(3);
// value2 = analogLSB1 + (analogMSB1 * 256);
// Serial.print("V from Sensor 2 = ");
// Serial.println(value2);
// turn the Relay1 on
if (value1>=minVal&&value1<= maxVal)
{
digitalWrite(Relay1, HIGH);}
if(digitalRead (Relay1) == HIGH){
//turn on millis
start=millis();
delay(100); // for debounce
Serial.println("Started...");
if (digitalRead (Relay1) == LOW)
{
time = millis();
finished = millis();
elapsed = finished - start;
displayResult();
delay (100);
}
}
else
{
digitalWrite(Relay1, LOW);
}
//turn on relay 2 during millis period
if (Relay1 == LOW && Relay3 == LOW && Relay4 == LOW && previous == LOW && millis()- time > debounce)
{
digitalWrite(Relay2, HIGH);
delay(elapsed);
digitalWrite(Relay2, LOW);
delay (200);
}
//turn on relay 3 during millis period
if (Relay1 == LOW && Relay2 == LOW && Relay4 == LOW && previous == LOW && millis()- time > debounce)
{
digitalWrite(Relay3, HIGH);
delay(elapsed);
digitalWrite (Relay3, LOW);
}
delay (200);
//turn on relay 2 during millis period
if (Relay1 == LOW && Relay2 == LOW && Relay3 == LOW && previous == LOW && millis()- time > debounce)
{
digitalWrite(Relay4, HIGH);
delay (elapsed);
digitalWrite (Relay4, LOW);
}
delay (200);
Series2_Rx.ino (4.96 KB)