Hello,
I have a question that I can't quite figure out, at least I know what probably causes it, but I don't see a solution.
What do we have: 3 buttons and 3 relays
When I turn switch 1 on, relay 1 turns on properly, when I turn the switch off again, relay 1 also turns off again, the same with switch 2, when we press it, relay 2 turns on and turns off again when we turn switch 2 off again.
When I turn switch 1 and switch 2 both on, both relays 1 and 2 are also on, the intention is that when I press push button 3, relay 1 and relay 2 should go out and relay 3 should be on as long as I press this push button, at the moment I release push button 3, relay 1 and relay 2 should turn on again, because it was still on.
With the sketch I made it works but the relays vibrate and that is probably because in the loop the command is given, which is given earlier in the sketch, that if the button is on the relays must also be on.
How do I get Push button 3 to have priority to turn off relays 1 and 2 as long as it is active. This is my sketch, hopefully someone can help me, it must be something small but I can't see it right now
void loop() {
buttonState1 = digitalRead(tlButton);
if (buttonState1 == HIGH) {
digitalWrite(ledPin1, LOW); //turn relais 1 off
} else {
digitalWrite(ledPin1, HIGH); //turn relais 1 on
}
buttonState2 = digitalRead(mdButton);
if (buttonState2 == HIGH) {
digitalWrite(ledPin2, LOW); //turn relais 2 off
} else {
digitalWrite(ledPin2, HIGH); //turn relais 2 on
}
buttonState3 = digitalRead(zhButton);
if (buttonState3 == HIGH) {
digitalWrite(ledPin3, LOW); //turn relais 3 on
digitalWrite(ledPin2, LOW); //turn relais 2 off
digitalWrite(ledPin1, LOW); //turn relais 1 off
} else {
digitalWrite(ledPin3, HIGH); //turn relais 1 off
digitalWrite(ledPin2, HIGH); //turn relais 2 on
digitalWrite(ledPin1, HIGH); //turn relais 1 on
}
}