from machine import Pin
import time
# Define LED pins (check your wiring!)
red_led = Pin(0, Pin.OUT)
green_led = Pin(1, Pin.OUT)
blue_led = Pin(2, Pin.OUT)
yellow_led = Pin(3, Pin.OUT)
# Function to blink an LED
def blink_led(led_pin):
led_pin.on() # Turn the LED on
time.sleep(0.5) # Wait for 500ms
led_pin.off() # Turn the LED off
time.sleep(0.5) # Wait for 500ms
# Debug message to ensure Pico is running
print("Raspberry Pi Pico LED Blink Program")
print("Press 'U' for Up, 'D' for Down, 'R' for Right, 'L' for Left to blink an LED.")
# Main program loop
while True:
# Read user input via REPL (serial terminal)
user_input = input().strip().upper() # Read input from the serial terminal
# Debugging: print the input for troubleshooting
print(f"User input received: {user_input}")
# Check for valid key presses and blink the corresponding LED
if user_input == "U":
print("Blinking Red LED (Up Arrow)")
blink_led(red_led) # Blink red LED for up arrow
elif user_input == "D":
print("Blinking Green LED (Down Arrow)")
blink_led(green_led) # Blink green LED for down arrow
elif user_input == "R":
print("Blinking Blue LED (Right Arrow)")
blink_led(blue_led) # Blink blue LED for right arrow
elif user_input == "L":
print("Blinking Yellow LED (Left Arrow)")
blink_led(yellow_led) # Blink yellow LED for left arrow
else:
print("Invalid input! Please press U, D, R, or L.")