I have been trying to build a circuit with 4 buttons and 1 rgb LED, where every color from the LED goes on while two seperate buttons are pressed. I have build this, sometimes it works perfectly, but something the light stays on or goes on with only 1 button etc.
Can anyone see where the problem is? Or should i be doing it totally different? I'm new to this and no idea what i am doing.
void setup() {
pinMode(5,INPUT);
pinMode(6,INPUT);
pinMode(7,INPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,INPUT);
}
void loop() {
if (digitalRead(5) ==HIGH)
if (digitalRead(6) ==HIGH){
digitalWrite(9,HIGH);
}
else{digitalWrite(9,LOW);
}
if (digitalRead(12) ==HIGH)
if (digitalRead(5) ==HIGH){
digitalWrite(10,HIGH);
}
else{digitalWrite(10,LOW);
}
if (digitalRead(7) ==HIGH)
if (digitalRead(6) ==HIGH){
digitalWrite(11,HIGH);
}
else{digitalWrite(11,LOW);
}
}
Picture of my circuit
Thanks ![]()
