#define t1 20
int nanoPin[16] = {
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17
};
const int chCount = sizeof(nanoPin) / sizeof(nanoPin[0]);
// Global variables since they are used every time the loop is called
unsigned int stack = 0;
unsigned int chaser = chCount-1;
void setup() {
for (int op=0; op < chCount; op++) {
pinMode(nanoPin[op], OUTPUT);
delay(10);
}
}
void loop(){
// Go throught the LEDs once per loop
// Turn on the chaser LED, turn off all LEDs not already "stacked"
for (unsigned int led=stack; led < chCount; led++) {
if (led == chaser) {
digitalWrite(nanoPin[led], HIGH);
}
else if (led != stack) {
digitalWrite(nanoPin[led], LOW);
}
}
// the delay
delay(t1);
// Move the chaser LED down the line
chaser--;
// Reset the chaser when hitting bottom
if (chaser >= chCount) {
chaser = chCount-1;
// Increase the stack
stack++;
// Reset the stack when reaching top
stack %= chCount;
}
}