const int ledPins[] = {2,4,5,16,17,18,19,21}; // GPIO pins connected to LEDs
const int numLeds = 8;
int count = 255; // Start count at 255 (all LEDs on)
void setup() {
// Set all LED pins as OUTPUT
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Display the current count on the LEDs
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], (count >> i) & 1);
}
// Delay for a second
delay(1000);
// Decrement the count
count--;
// Reset the count if it goes below 0
if (count < 0) {
count = 255;
}
}