#The traffic light automatically switches on the Red, yellow and green light.
#When the red light is ON, the buzzer informs the pedisterian to cross the road
#till the Red light is on
import machine
import utime
import _thread
import time
from machine import Pin
from time import sleep
led_red = machine.Pin(15, machine.Pin.OUT)
led_yellow = machine.Pin(14, machine.Pin.OUT)
led_green = machine.Pin(13, machine.Pin.OUT)
button = Pin(16, machine.Pin.IN)
buzzer = machine.Pin(12, machine.Pin.OUT)
global button_pressed
button_pressed = False
while True:
logic_state = button.value()
if logic_state == True: # if push_button pressed
led_red.value(1)
buzzer.value(1)
utime.sleep(10)
led_red.value(0)
buzzer.value(0)
led_yellow.value(1)
utime.sleep(2)
led_yellow.value(0)
led_green.value(1)
utime.sleep(5)
led_green.value(0)
led_yellow.value(1)
utime.sleep(2)
led_yellow.value(0)
else:
led_red.value(0)
led_yellow.value(0)
led_green.value(0)