I'm trying to individually control 3 LEDs with 3 toggle switches. This is the code I'm using
#define LED_PIN1 2
#define BUTTON_PIN1 14
#define LED_PIN2 3
#define BUTTON_PIN2 15
#define LED_PIN3 4
#define BUTTON_PIN3 16
void setup() {
pinMode(LED_PIN1, OUTPUT);
pinMode(BUTTON_PIN1, INPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(BUTTON_PIN2, INPUT);
pinMode(LED_PIN3, OUTPUT);
pinMode(BUTTON_PIN3, INPUT);
}
void loop() {
if (digitalRead(BUTTON_PIN1) == HIGH) {
digitalWrite(LED_PIN1, HIGH);
}
if (digitalRead(BUTTON_PIN1) == LOW) {
digitalWrite(LED_PIN1, LOW);
}
if (digitalRead(BUTTON_PIN2) == HIGH) {
digitalWrite(LED_PIN2, HIGH);
}
if (digitalRead(BUTTON_PIN2) == LOW) {
digitalWrite(LED_PIN2, LOW);
}
if (digitalRead(BUTTON_PIN3) == HIGH) {
digitalWrite(LED_PIN3, HIGH);
}
if (digitalRead(BUTTON_PIN3) == LOW) {
digitalWrite(LED_PIN3, LOW);
}
}
The problem is that this code is causing all 3 LEDs to turn on or off together when any one of the three toggle switches is pushed. Can someone explain why this is happening? Also, what do I need to change so that each LED can be individually controlled?
Thanks!

