const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}; // Pins for 10 LEDs
const int buttonPin = 12; // Pin for the input button
int buttonState = 0; // Variable for reading the button status
void setup() {
// Set the LED pins as output
for (int i = 0; i < 10; i++) {
pinMode(ledPins[i], OUTPUT);
}
// Set the button pin as input
pinMode(buttonPin, INPUT);
}
void loop() {
// Read the state of the button (HIGH or LOW)
buttonState = digitalRead(buttonPin);
// If the button is pressed (HIGH), turn on the LEDs
if (buttonState == HIGH) {
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], HIGH); // Turn the LED on
delay(100); // Delay to create a sequence effect
}
} else { // If the button is not pressed, turn off all the LEDs
for (int i = 0; i < 10; i++) {
digitalWrite(ledPins[i], LOW); // Turn the LED off
}
}
}