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 red leds and turn off yellow and green leds
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
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
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()