from machine import Pin
import time
# Define GPIO pins for the LEDs (D0 - D3)
led_pins = [15, 14, 13, 12]
# Initialize LED pins as output
leds = [Pin(pin_num, Pin.OUT) for pin_num in led_pins]
def display_binary(value):
# Display the 4-bit binary representation on the LEDs
for i in range(4):
bit = (value >> i) & 1
leds[i].value(bit)
# Main loop
counter = 0
while True:
display_binary(counter)
print(f"Counter: {counter} (Binary: {counter:04b})") # <-- Added print here
time.sleep(1) # Wait for 1 second
counter = (counter + 1) % 16 # Loop back after 15