#
# Traffic Light
#
import board
import digitalio
import time
# set up LED's and Direction
red = digitalio.DigitalInOut(board.GP12)
red.direction = digitalio.Direction.OUTPUT
yellow = digitalio.DigitalInOut(board.GP11)
yellow.direction = digitalio.Direction.OUTPUT
green = digitalio.DigitalInOut(board.GP10)
green.direction = digitalio.Direction.OUTPUT
# main loop
while True:
# Switch from red light to green light then wait
red.value = False
green.value = True
time.sleep(3)
# Switch from green light to yellow light then wait a short time
green.value = False
yellow.value = True
time.sleep(1)
# Switch from the yellow light to the red light then wait
yellow.value = False
red.value = True
time.sleep(3)