traffic

Here I post some raw python code that implements an acoustic system booking for people passing through the street.

from gpiozero import Button,LED,Buzzer
from time import sleep

red = LED(25)
yellow = LED(8)
green = LED(7)
button = Button(2)
buzzer = Buzzer(15)
booking = False
def activate_booking():
    global booking
    booking = True
button.when_pressed = activate_booking

while True:
    green.on()
    sleep(5)
    yellow.on()
    sleep(1)
    yellow.off()
    green.off()
    if not booking:
        red.on()
        sleep(10)
        red.off()
    else:
        red.on()
        for i in range(5):
            buzzer.on()
            sleep(1)
            buzzer.off()
            sleep(1)
        red.off()
        booking = False