import machine
import time
# Define the LED pins based on the mapping (GP0 to GP9 correspond to Arduino Mega pins 2-11)
led_pins = [
machine.Pin(0, machine.Pin.OUT), # maps Arduino Mega pin 2 -> Pico GP0
machine.Pin(1, machine.Pin.OUT), # maps Arduino Mega pin 3 -> Pico GP1
machine.Pin(2, machine.Pin.OUT), # maps Arduino Mega pin 4 -> Pico GP2
machine.Pin(3, machine.Pin.OUT), # maps Arduino Mega pin 5 -> Pico GP3
machine.Pin(4, machine.Pin.OUT), # maps Arduino Mega pin 6 -> Pico GP4
machine.Pin(5, machine.Pin.OUT), # maps Arduino Mega pin 7 -> Pico GP5
machine.Pin(6, machine.Pin.OUT), # maps Arduino Mega pin 8 -> Pico GP6
machine.Pin(7, machine.Pin.OUT), # maps Arduino Mega pin 9 -> Pico GP7
machine.Pin(8, machine.Pin.OUT), # maps Arduino Mega pin 10 -> Pico GP8
machine.Pin(9, machine.Pin.OUT) # maps Arduino Mega pin 11 -> Pico GP9
]
# Ensure all LEDs are initially off.
for pin in led_pins:
pin.value(0)
while True:
# Forward cycle: light each LED for 2 seconds
for pin in led_pins:
pin.value(1) # Turn LED on
time.sleep(2) # Delay for 2 seconds
pin.value(0) # Turn LED off
# Reverse cycle: light each LED for 2 seconds in reverse order
for pin in reversed(led_pins):
pin.value(1) # Turn LED on
time.sleep(2) # Delay for 2 seconds
pin.value(0) # Turn LED off