# A short program to sequentially turn on 8 LEDs
# connected to GPIO 18, 19, 20, 21, 22, 26, 27, 28
# for a quarter of a second and then turn them off
# and reverse the procedure
#
#
#
# Import the modules used in the script
import time
import machine
# Define Constants
NUM_LEDS = 8
led_list = [18, 19, 20, 21, 22, 26, 27, 28]
# Configure the GPIO to BCM numbering scheme and set pins to output mode
for x in range(NUM_LEDS):
led_pin = machine.Pin(led_list[x], machine.Pin.OUT)
led_pin.off() # Set initial state to LOW (off)
print("Sequential LED Sequence")
print("Press CTRL + C to quit.")
# Main loop
try:
while True:
for x in range(NUM_LEDS):
led_pin = machine.Pin(led_list[x], machine.Pin.OUT)
led_pin.on() # Turn LED on
time.sleep(0.25)
led_pin.off() # Turn LED off
# If CTRL+C is pressed, the main loop is broken
except KeyboardInterrupt:
print("Quitting")
# Clean up GPIO pins
for x in range(NUM_LEDS):
led_pin = machine.Pin(led_list[x], machine.Pin.OUT)
led_pin.off() # Turn off all LEDs