from machine import Pin
import time
segments = [Pin(i, Pin.OUT) for i in range(7)]
dp = Pin(7, Pin.OUT)
colon = Pin(8, Pin.OUT)
digits = [Pin(10,Pin.OUT),Pin(11,Pin.OUT),Pin(12,Pin.OUT),Pin(13,Pin.OUT)]
red = Pin(27,Pin.OUT)
yellow = Pin(26,Pin.OUT)
green = Pin(22,Pin.OUT)
numbers=[
[1,1,1,1,1,1,0],
[0,1,1,0,0,0,0],
[1,1,0,1,1,0,1],
[1,1,1,1,0,0,1],
[0,1,1,0,0,1,1],
[1,0,1,1,0,1,1],
[1,0,1,1,1,1,1],
[1,1,1,0,0,0,0],
[1,1,1,1,1,1,1],
[1,1,1,1,0,1,1]
]
def show(sec):
m = sec//60
s = sec%60
d1=m//10
d2=m%10
d3=s//10
d4=s%10
vals=[d1,d2,d3,d4]
for _ in range(80):
for i in range(4):
digits[i].value(1)
for j in range(7):
segments[j].value(numbers[vals[i]][j])
colon.value(1)
time.sleep_ms(2)
digits[i].value(0)
def countdown(sec):
for i in range(sec,-1,-1):
t=time.time()
while time.time()-t<1:
show(i)
while True:
red.on()
countdown(60)
red.off()
yellow.on()
time.sleep(5)
yellow.off()
green.on()
countdown(60)
green.off()
yellow.on()
time.sleep(5)