from machine import Pin
import time
LED_RED_1 = Pin(2, Pin.OUT)
LED_YELLOW_1 = Pin(3, Pin.OUT)
LED_GREEN_1 = Pin(4, Pin.OUT)
LED_RED_2 = Pin(8, Pin.OUT)
LED_YELLOW_2 = Pin(9, Pin.OUT)
LED_GREEN_2 = Pin(10, Pin.OUT)
def init_pins():
LED_RED_1.value(0)
LED_YELLOW_1.value(0)
LED_GREEN_1.value(0)
LED_RED_2.value(0)
LED_YELLOW_2.value(0)
LED_GREEN_2.value(0)
def traffic_light_sequence():
while True:
# Turn on the red LEDs and turn off the yellow and green LEDs for both traffic lights
LED_RED_1.value(1)
LED_YELLOW_1.value(0)
LED_GREEN_1.value(0)
LED_RED_2.value(1)
LED_YELLOW_2.value(0)
LED_GREEN_2.value(0)
time.sleep(3)
# First traffic light: Red -> Green -> Yellow -> Red
LED_RED_1.value(0)
LED_GREEN_1.value(1)
time.sleep(3)
LED_GREEN_1.value(0)
LED_YELLOW_1.value(1)
time.sleep(1)
LED_YELLOW_1.value(0)
LED_RED_1.value(1)
time.sleep(1)
# Second traffic light: Red -> Green -> Yellow -> Red
LED_RED_2.value(0)
LED_GREEN_2.value(1)
time.sleep(3)
LED_GREEN_2.value(0)
LED_YELLOW_2.value(1)
time.sleep(1)
LED_YELLOW_2.value(0)
LED_RED_2.value(1)
time.sleep(1)
def main():
init_pins()
traffic_light_sequence()
if __name__ == "__main__" :
main()