# Import necessary modules
from machine import Pin # To control GPIO pins
from time import sleep # To create delays
# Step 1: Initialize the LED pins as output
# Create a Pin object for each LED and set it to OUTPUT mode
green_led = Pin(17, Pin.OUT) # Green LED connected to GPIO 17
yellow_led = Pin(18, Pin.OUT) # Yellow LED connected to GPIO 18
red_led = Pin(19, Pin.OUT) # Red LED connected to GPIO 19
# Step 2: Define a function to blink a single LED
def blink_led(led, duration=3):
led.on() # Turn the LED ON
sleep(duration) # Wait for the specified duration (default 3 seconds)
led.off() # Turn the LED OFF
sleep(0.5) # Short delay before the next action (optional)
# Step 3: Use an infinite loop to blink each LED one by one
while True:
print("Green LED ON") # Print message for debugging or monitoring
blink_led(green_led) # Blink the green LED
print("Yellow LED ON") # Print message for debugging
blink_led(yellow_led) # Blink the yellow LED
print("Red LED ON") # Print message for debugging
blink_led(red_led) # Blink the red LED