from machine import Pin
from time import sleep
# List of GPIO pins connected to LEDs
led_list = [6, 7, 8, 9, 10, 11, 12, 13]
# Initialize a list to hold pin objects for LEDs
led = [None] * 8
# Assign Pin objects to the led list
for i in range(8):
led[i] = Pin(led_list[i], Pin.OUT)
# Function to turn off all LEDs
def turn_off_all_leds():
for i in range(8):
led[i].value(0)
# Function to run a light back and forth
def running_light_back_and_forth(frequency):
delay = 1 / frequency
# Light up LEDs from left to right
for i in range(8):
led[i].value(1)
sleep(delay)
led[i].value(0)
# Light up LEDs from right to left
for i in range(6, -1, -1):
led[i].value(1)
sleep(delay)
led[i].value(0)
# Main loop
while True:
running_light_back_and_forth(10)