const int ledPins[] = {23,22,17,16}; // LED GPIO pins
const int buttonPin = 15; // Button GPIO pin
volatile int counter = 0; // Counter value
void setup() {
for (int i = 0; i < 4; i++) {
pinMode(ledPins[i], OUTPUT); // Set LED pins as OUTPUT
}
pinMode(buttonPin, INPUT_PULLUP); // Set button pin as INPUT_PULLUP
attachInterrupt(buttonPin, buttonPressed, FALLING); // Interrupt on button press
}
void loop() {
displayCounter(); // Display counter value on LEDs
delay(200); // Debounce delay
}
void buttonPressed() {
counter = (counter + 1) % 16; // Increment counter and reset after 15
}
void displayCounter() {
for (int i = 0; i < 4; i++) {
digitalWrite(ledPins[i], (counter >> i) & 0x01); // Display binary value of counter
}
}