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

button = Button(21)
lights = TrafficLights(25,8,7)
buzzer = Buzzer(15)
timer = 0

def pedestrian():
    lights.green.off()
    lights.amber.on()
    sleep(3)
    lights.amber.off()
    lights.red.on()
    buzzer.beep(.5,.5)
    sleep(4)
    buzzer.beep(.1,.1)
    sleep(2)
    lights.off()
    buzzer.off()
    lights.green.on()
    return;

while True:
    if button.is.pressed:
        pedestrian()
        timer = 0
    else:
        timer = timer+.1
        sleep(.1)
        
    if timer < 20:
        lights.green.on()
    else:
        pedestrian()
        timer = 0