Hello guys,
I have a code so when i press a button(1) my relay will switch for an given amount of seconds and a 2nd button(2) that will switch the relay for as long as the button is pressed. now the problem is button 1 works perfectly but button 2 wont work only if i press button 1 and then press button 2, only then button to will keep the relay switched for as long as it is pressed. its weird that button 2 wont switch the relay because if i press it it will light up the led of the relay but you dont hear the clicking.
could you guys lend me a hand.
this is my code btw
ps Knop = Button (knop is a dutch word)
#define Relay 10
#define Knop1 4
#define Knop2 3
void setup() {
pinMode(Knop1, INPUT_PULLUP);
pinMode(Knop2, INPUT_PULLUP);
pinMode(Relay, OUTPUT);
}
void loop() {
digitalWrite(Relay,HIGH);
if (digitalRead(Knop1)== LOW){
digitalWrite(Relay,LOW);
delay(4000);
digitalWrite(Relay,HIGH);
}
if (digitalRead(Knop2)== LOW){
digitalWrite(Relay,LOW);
( digitalRead(Knop2)== HIGH);{
digitalWrite(Relay,HIGH);
}
}
}