import tm1637
from machine import Pin
from utime import sleep
tm1 = tm1637.TM1637(clk=Pin(0), dio=Pin(1))
tm2 = tm1637.TM1637(clk=Pin(2), dio=Pin(3))
tm3 = tm1637.TM1637(clk=Pin(4), dio=Pin(5))
tm4 = tm1637.TM1637(clk=Pin(6), dio=Pin(7))
btn_up = Pin(8, Pin.IN, Pin.PULL_UP)
btn_down = Pin(9, Pin.IN, Pin.PULL_UP)
counter = 0
def update_displays():
num = f"{counter:04}"
tm1.show(num)
tm2.show(num)
tm3.show(num)
tm4.show(num)
def main_loop():
global counter
update_displays()
while True:
btn_up_pressed = not btn_up.value()
btn_down_pressed = not btn_down.value()
if btn_up_pressed:
counter += 1
if counter > 9999:
counter = 0
update_displays()
while not btn_up.value():
sleep(0.1)
if btn_down_pressed:
counter -= 1
if counter < 0:
counter = 9999
update_displays()
while not btn_down.value():
sleep(0.1)
sleep(0.1)
main_loop()