const byte BUTTON_PIN = 2;
const byte LEDS_PIN[7] = { 7, 8, 9, 10, 11, 12, 13 };
void setup() {
for (byte led: LEDS_PIN)
pinMode(led, OUTPUT);
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
byte buttonIsPressed = false;
void loop() {
byte buttonCurrentState = digitalRead(BUTTON_PIN);
if (buttonCurrentState == LOW && !buttonIsPressed) {
buttonIsPressed = true;
ledLightsBlink4Times();
} else {
buttonIsPressed = false;
}
}
void ledLightsBlink4Times() {
for (byte loop=0; loop<4; loop++) {
ledLightsSolid();
if (delayLoop(150)) return;
ledLightsOff();
if (delayLoop(400)) return;
}
}
void ledLightsOff() {
for (byte led: LEDS_PIN)
digitalWrite(led, LOW);
}
void ledLightsSolid() {
for (byte led: LEDS_PIN)
digitalWrite(led, HIGH);
}
boolean delayLoop(unsigned int delayInterval) {
unsigned long startMillis = millis();
do {
//if (digitalRead(BUTTON_PIN) == LOW) return true;
} while (millis() - startMillis < delayInterval);
return false;
}