from machine import Pin
import time
led_pins = [23, 22, 19, 18, 0, 4, 16, 17]
switch_pin = 14
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
switch = Pin(switch_pin, Pin.IN, Pin.PULL_UP)
prev_switch_state = 1
def move_right():
for i in range(len(leds)):
leds[i].on()
time.sleep(0.2)
leds[i].off()
def move_left():
for i in range(len(leds) - 1, -1, -1):
leds[i].on()
time.sleep(0.2)
leds[i].off()
while True:
switch_state = switch.value()
if switch_state == 0 and prev_switch_state == 1:
move_right()
elif switch_state == 1 and prev_switch_state == 0:
move_left()
prev_switch_state = switch_state