#Aim : To design a traffic lighting system with timer with raspberry pi
from machine import Pin
import time
red = Pin(27, Pin.OUT)
yellow = Pin(26, Pin.OUT)
green = Pin(22, Pin.OUT)
seg1 = [Pin(i, Pin.OUT) for i in range(0,7)]
seg2 = [Pin(i, Pin.OUT) for i in [7,8,9,10,11,12,13]]
digits = [
[1,1,1,1,1,1,0], #0
[0,1,1,0,0,0,0], #1
[1,1,0,1,1,0,1], #2
[1,1,1,1,0,0,1], #3
[0,1,1,0,0,1,1], #4
[1,0,1,1,0,1,1], #5
[1,0,1,1,1,1,1], #6
[1,1,1,0,0,0,0], #7
[1,1,1,1,1,1,1], #8
[1,1,1,1,0,1,1] #9
]
def display(num):
tens = num // 10
ones = num % 10
for i in range(7):
seg1[i].value(digits[tens][i])
seg2[i].value(digits[ones][i])
def countdown(seconds):
for i in range(seconds, -1, -1):
display(i)
time.sleep(1)
while True:
red.on()
yellow.off()
green.off()
countdown(60)
red.off()
yellow.on()
green.off()
time.sleep(5)
red.off()
yellow.off()
green.on()
time.sleep(60)
red.off()
yellow.on()
green.off()
time.sleep(5)