const byte LED_PINS[] = {2,3,4,5,6,7,8,9}; // piny Arduino, do których podłączone są LEDy
const byte BUTTON_PIN = 13; // pin Arduino, do którego podłączony jest przycisk
void setup() {
for (int i = 0; i < sizeof(LED_PINS); i++) {
pinMode(LED_PINS[i], OUTPUT);
}
pinMode(BUTTON_PIN, INPUT_PULLUP);
}
void loop() {
static byte counter;
static long buttonPressTime;
static bool buttonPressed;
if ((millis() - buttonPressTime) > 100) {
if ((digitalRead(BUTTON_PIN) == LOW) && !buttonPressed) {
buttonPressTime = millis();
buttonPressed = true;
counter = (counter+1) % 9;
setLed(counter);
}
else if ((digitalRead(BUTTON_PIN) == HIGH) && buttonPressed) {
buttonPressed = false;
buttonPressTime = millis();
}
}
}
void setLed(byte ledNo) {
for (int i = 0; i < sizeof(LED_PINS); i++) {
digitalWrite(LED_PINS[i], (i+1 == ledNo)? HIGH : LOW);
}
}