import machine
import time

# Setup GPIO pins
pins = {
    "lane_2_green": machine.Pin(2, machine.Pin.OUT),
    "lane_4_green": machine.Pin(3, machine.Pin.OUT),
    "lane_4_red": machine.Pin(4, machine.Pin.OUT),
    "lane_1_green": machine.Pin(17, machine.Pin.OUT),
    "lane_3_green": machine.Pin(27, machine.Pin.OUT),
    "lane_3_red": machine.Pin(22, machine.Pin.OUT),
    "lane_1_yellow": machine.Pin(10, machine.Pin.OUT),
    "lane_3_yellow": machine.Pin(9, machine.Pin.OUT),
    "lane_1_red": machine.Pin(11, machine.Pin.OUT),
    "lane_2_yellow": machine.Pin(13, machine.Pin.OUT),
    "lane_4_yellow": machine.Pin(6, machine.Pin.OUT),
    "lane_2_red": machine.Pin(5, machine.Pin.OUT),
}

def set_all_pins(value):
    for pin in pins.values():
        pin.value(value)

while True:
    # Turn off all signals
    set_all_pins(0)

    print("Green Signal for Lane 2 & Lane 4 & Red Signal for Lane 1 & Lane 3")
    pins["lane_2_green"].value(1)
    pins["lane_4_green"].value(1)
    pins["lane_1_red"].value(1)
    pins["lane_3_red"].value(1)
    time.sleep(8)

    print("Yellow Signal for Lane 2 & Lane 4")
    pins["lane_2_green"].value(0)
    pins["lane_4_green"].value(0)
    pins["lane_3_red"].value(0)
    pins["lane_1_red"].value(0)
    pins["lane_2_yellow"].value(1)
    pins["lane_4_yellow"].value(1)
    time.sleep(6)

    print("Green Signal for Lane 1 & Lane 3 & Red signal for Lane 2 & Lane 4")
    pins["lane_2_yellow"].value(0)
    pins["lane_4_yellow"].value(0)
    pins["lane_1_green"].value(1)
    pins["lane_3_green"].value(1)
    pins["lane_4_red"].value(1)
    pins["lane_2_red"].value(1)
    time.sleep(8)

    print("Yellow Signal for Lane 1 & Lane 3")
    pins["lane_1_green"].value(0)
    pins["lane_3_green"].value(0)
    pins["lane_4_red"].value(0)
    pins["lane_2_red"].value(0)
    pins["lane_1_yellow"].value(1)
    pins["lane_3_yellow"].value(1)
    time.sleep(4)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT