// Function to initialize the LED pins and button pin.
void initializePins() {
// Set LED pins as OUTPUT.
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
// Set button pin as INPUT.
pinMode(2, INPUT);
}
// Function to turn on the LEDs based on the button press using switch case.
void turnOnLEDs() {
// Read the state of the button.
int buttonState = digitalRead(2);
// Use switch case to determine which LED to turn on based on the button state.
switch (buttonState) {
case HIGH:
digitalWrite(13, HIGH);
digitalWrite(12, HIGH);
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
break;
case LOW:
digitalWrite(13, LOW);
digitalWrite(12, LOW);
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
break;
}
}
void setup() {
// Call the function to initialize the pins.
initializePins();
}
void loop() {
// Call the function to turn on the LEDs based on the button press.
turnOnLEDs();
}