import tm1637
from machine import Pin
from utime import sleep_ms
# Initialize the TM1637 display
tm = tm1637.TM1637(clk=Pin(2), dio=Pin(3))
# Initialize buttons on Pin 4 (increase) and Pin 5 (decrease)
button_increase = Pin(28, Pin.IN, Pin.PULL_UP)
button_decrease = Pin(26, Pin.IN, Pin.PULL_UP)
# Function to display a number on the TM1637
def display_number(number):
number_str = f"{number:04d}"
tm.number(int(number_str))
# Initialize the counter
count = 0
while True:
# Display the current count
display_number(count)
# Check if the increase button is pressed
if not button_increase.value():
count += 1
sleep_ms(200) # Debounce and delay
# Check if the decrease button is pressed
if not button_decrease.value():
count -= 1
sleep_ms(200) # Debounce and delay
# Ensure the count stays within the 0-9999 range
count = max(0, min(count, 9999))