from machine import Pin
import time
red_pins = [5, 15, 22, 25]
yellow_pins = [2, 13, 26, 32]
green_pins = [4, 12, 27, 33]
def turn_on_led(pin_list, color):
for pin in pin_list:
led = Pin(pin, Pin.OUT)
led.value(0)
if color == "red":
led_index = 0
elif color == "yellow":
led_index = 1
else:
led_index = 2
led = Pin(pin_list[led_index], Pin.OUT)
led.value(1)
def traffic_light_sequence():
while True:
turn_on_led(red_pins, "red")
time.sleep(3)
turn_on_led(yellow_pins, "yellow")
time.sleep(1)
turn_on_led(green_pins, "green")
time.sleep(5)
traffic_light_sequence()