// Chaser no bloqueante con millis()
const int ledPins[] = {2,3,4,5,6,7};
const int NUM_LEDS = sizeof(ledPins) / sizeof(ledPins[0]);
int index = 0; // LED actual
int dir = 1; // dirección (1 = adelante, -1 = atrás)
unsigned long lastMillis = 0;
const unsigned long interval = 120;
void setup() {
for (int i = 0; i < NUM_LEDS; i++)
pinMode(ledPins[i], OUTPUT);
}
void loop() {
unsigned long now = millis();
if (now - lastMillis >= interval) {
lastMillis = now;
// Apaga todos y enciende el LED actual
for (int i = 0; i < NUM_LEDS; i++) {
digitalWrite(ledPins[i], (i == index) ? HIGH : LOW);
}
// Mover el índice en la dirección actual
index += dir;
// Rebotar en los extremos (ping-pong)
if (index >= NUM_LEDS) {
index = NUM_LEDS - 2; // corrige y rebota
dir = -1;
}
else if (index < 0) {
index = 1; // corrige y rebota
dir = 1;
}
}
// aquí puedes manejar botones, sensores, etc., sin quedar bloqueado
}