const int LED1 = 11; // LED1 connected to digital pin 13
const int LED2 = 10; // LED2 connected to digital pin 12
const int LED3 = 9; // LED3 connected to digital pin 11
const int button1 = 2; // button1 connected to digital pin 2
const int button2 = 3; // button2 connected to digital pin 3
const int button3 = 4; // button3 connected to digital pin 4
void setup()
{
pinMode(LED1, OUTPUT); // sets the LED1 as an output
pinMode(LED2, OUTPUT); // sets the LED2 as an output
pinMode(LED3, OUTPUT); // sets the LED3 as an output
pinMode(button1, INPUT_PULLUP); // sets the button1 as an input with pull-up resistor
pinMode(button2, INPUT_PULLUP); // sets the button2 as an input with pull-up resistor
pinMode(button3, INPUT_PULLUP); // sets the button3 as an input with pull-up resistor
}
void loop() {
// reads the button1 state and turns on/off LED1 accordingly
if (digitalRead(button1) == LOW) {
digitalWrite(LED1, HIGH);
} else {
digitalWrite(LED1, LOW);
}
// reads the button2 state and turns on/off LED2 accordingly
if (digitalRead(button2) == LOW) {
digitalWrite(LED2, HIGH);
} else {
digitalWrite(LED2, LOW);
}
// reads the button3 state and turns on/off LED3 accordingly
if (digitalRead(button3) == LOW) {
digitalWrite(LED3, HIGH);
} else {
digitalWrite(LED3, LOW);
}
}