from machine import Pin
import time
# Define the GPIO pins for each LED
red_pin = Pin(0, Pin.OUT) # GPIO 0
yellow_pin = Pin(2, Pin.OUT) # GPIO 2
green_pin = Pin(4, Pin.OUT) # GPIO 4
# Function to switch off all LEDs
def all_off():
red_pin.off()
yellow_pin.off()
green_pin.off()
# Function to display red light
def red_light():
all_off()
red_pin.on()
# Function to display yellow light
def yellow_light():
all_off()
yellow_pin.on()
# Function to display green light
def green_light():
all_off()
green_pin.on()
# Main program loop
while True:
# Red light for 5 seconds
red_light()
time.sleep(5)
# Yellow light for 2 seconds
yellow_light()
time.sleep(2)
# Green light for 5 seconds
green_light()
time.sleep(5)