from machine import Pin
import time
# Define the pins for each LED
red_pin = Pin(1, Pin.OUT)
yellow_pin = Pin(5, Pin.OUT)
green_pin = Pin(10, Pin.OUT)
# Define the time delay for each traffic light state in seconds
red_delay = 5
yellow_delay = 2
green_delay = 5
# Define the traffic light sequence
def traffic_light_sequence():
while True:
# Red light
red_pin.on()
yellow_pin.off()
green_pin.off()
time.sleep(red_delay)
# Green light
red_pin.off()
yellow_pin.off()
green_pin.on()
time.sleep(green_delay)
# Blink the green light
for i in range(3):
green_pin.on()
time.sleep(0.5)
green_pin.off()
time.sleep(0.5)
# Yellow light
red_pin.off()
yellow_pin.on()
green_pin.off()
time.sleep(yellow_delay)
# Run the traffic light sequence
traffic_light_sequence()