from machine import Pin, PWM
import time,random,tm1637
rLED = PWM(Pin(12)) # 控制紅燈
gLED = PWM(Pin(13)) # 控制綠燈
bLED = PWM(Pin(14)) # 控制藍燈
tm = tm1637.TM1637(clk=Pin(22), dio=Pin(23))
def count_down(s,color):
if color == 'red':
for y in range(s,-1,-1):
tm.numbers(0,y)
time.sleep(1)
else:
for y in range(s,-1,-1):
tm.numbers(0,y)
if y==10:
yellow_light()
time.sleep(1)
def red_light(s):
rLED.duty(225)
gLED.duty(0)
bLED.duty(0)
count_down(s,'red')
def green_light(s):
rLED.duty(0)
gLED.duty(225)
bLED.duty(0)
count_down(s,'green')
def yellow_light():
rLED.duty(225)
gLED.duty(225)
bLED.duty(0)
gs = eval(input("Green light second:"))
rs = eval(input("Red light second:"))
for x in range(20):
if x%2 == 0:
green_light(gs)
else:
red_light(rs)