const int buttonPin = 2;
const int motorPin = 8;
int ledPins[] = {3, 4, 5, 6, 7};
unsigned long previousTime = 0;
long interval = 1000;
int currentLED = 0;
int buttonState = 0;
int prevButtonState = 0;
void setup() {
for (int i = 0; i < 5; i++) {
pinMode(ledPins[i], OUTPUT);
}
pinMode(motorPin, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
digitalWrite(motorPin, LOW);
}
void loop() {
unsigned long currentTime = millis();
if (currentTime - previousTime > interval) {
previousTime = currentTime;
if (currentLED < 5) {
digitalWrite(ledPins[currentLED], HIGH);
currentLED++;
}
if (currentLED == 5) {
digitalWrite(motorPin, HIGH);
delay(5000);
digitalWrite(motorPin, LOW);
}
}
buttonState = digitalRead(buttonPin);
if (buttonState == LOW && prevButtonState == HIGH) {
for (int i = 0; i < 5; i++) {
digitalWrite(ledPins[i], LOW);
}
currentLED = 0;
previousTime = currentTime;
digitalWrite(motorPin, LOW);
}
prevButtonState = buttonState;
}
Comments