const int ledPins[] = {12, 13, 14, 15}; // LED pins
int counter = 15; // Start count at 15
void setup() {
// Initialize the LED pins as outputs
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT);
}
}
void loop() {
// Display the counter value on the LEDs
displayCounter(counter);
// Decrement the counter
counter--;
// Reset counter to 15 if it goes below 0
if (counter < 0) {
counter = 15;
}
delay(1000); // Wait for 1 second
}
void displayCounter(int count) {
for (int i = 0; i < 4; i++)
{
int bit = (count >> i) & 0x01; // Get the i-th bit of the count
digitalWrite(ledPins[i], bit); // Set the LED state
}
}