const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9};
const int buzzerPin = 10;
const int button1 = 11;
const int button2 = 12;
int currentLED = 0;
bool direction = true;
bool isRunning = false;
void setup() {
for (int i = 0; i < 8; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(buzzerPin, OUTPUT);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
}
void loop() {
bool button1State = digitalRead(button1) == LOW;
bool button2State = digitalRead(button2) == LOW;
if (button1State) {
isRunning = true;
delay(200);
}
if (button2State) {
direction = !direction;
delay(200);
}
if (isRunning) {
for (int i = 0; i < 8; i++) {
digitalWrite(ledPins[i], LOW);
}
digitalWrite(ledPins[currentLED], HIGH);
delay(100);
if (direction) {
currentLED++;
if (currentLED == 7) {
direction = false;
tone(buzzerPin, 1000, 200);
}
} else {
currentLED--;
if (currentLED == 0) {
direction = true;
tone(buzzerPin, 1000, 200);
}
}
}
}