import tm1637
import machine
import time
# CONFIG
tm = tm1637.TM1637(clk=machine.Pin(15), dio=machine.Pin(16))
tm.brightness(7) # ปรับความสว่าง (0-7)
# LEDS
led_red = machine.Pin(21, machine.Pin.OUT)
led_yellow = machine.Pin(20, machine.Pin.OUT)
led_green = machine.Pin(19, machine.Pin.OUT)
# PUSH BUTTON
btn = machine.Pin(17, machine.Pin.IN, machine.Pin.PULL_UP)
def clear_lights():
led_red.off()
led_yellow.off()
led_green.off()
def countdown(seconds):
for i in range(seconds, 0, -1):
tm.number(i)
time.sleep(1)
if __name__ == "__main__": # MAIN LOOP
while True:
clear_lights()
led_red.on()
tm.show("----")
if btn.value() == 0:
print("PEDESTRIAN BUTTON PUSHED")
countdown(10)
clear_lights()
led_green.on()
print("GREEN LIGHT")
countdown(15)
clear_lights()
led_yellow.on()
print("YELLOW LIGHT")
countdown(3)
print("RED LIGHT")
time.sleep(0.1) # A little delay keeps the heat awayLoading
esp32-s3-devkitc-1
esp32-s3-devkitc-1