#define UP 0
#define DOWN 1
byte ledPin[] = {8, 9, 10, 11, 12, 13};
void setup() {
//fazer setup dos pinos.
for (int i = 0; i<6; i++) {
pinMode(ledPin[i], OUTPUT);
}
};
void loop() {
LEDChange();
delay(1000); //Nao e bonito... mas e para demonstrar.
}
void LEDChange() {
static unsigned char sentido = DOWN;
static unsigned char LED = 5;
static unsigned char MaxH = 5;
if (sentido == UP) {
digitalWrite(ledPin[LED], LOW); //desliga o que estava.
digitalWrite(ledPin[LED++], HIGH); //liga o próximo.
if (LED > MaxH) { //se atingimos a altura máxima...
sentido = DOWN; //vamos para baixo.
LED = MaxH; //mas começamos de MaxH
}
} else { //sentido = DOWN
digitalWrite(ledPin[LED], LOW); //desliga o anterior
digitalWrite(ledPin[LED--], HIGH); //liga o próximo
if (LED < 0) { //se chegamos ao chão
LED = 0; // não vamos abaixo
sentido = UP; //vamos para cima
MaxH--; // mas não chegamos tão alto quanto antes.
if (MaxH < 0) { // Se atingimos repouso
MaxH = 5; // VOLTAMOS AO InÍCIO.
LED = 5;
sentido = DOWN;
}
}
}
}
Já está.