from machine import Pin
from utime import sleep
# Define a list of GPIO pins to which LEDs are connected
led_pins = [15, 2, 4, 5, 18, 19, 21, 22]
# Create a list of LED objects as Pin instances, set as outputs
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
# A simple function to turn all LEDs off
def turn_off_all_leds():
for led in leds:
led.value(0)
# A function to cycle through LEDs in a binary counting pattern
def cycle_leds_binary():
for i in range(256): # Assuming you want to go through 256 steps
for j in range(len(leds)):
# Calculate the bit value, but traverse the LEDs in reverse
bit_value = (i >> (len(leds) - 1 - j)) & 1
leds[j].value(bit_value)
sleep(0.5)
print("FInished counting!")
# Ensure all LEDs are initially off
turn_off_all_leds()
# Now cycle through LEDs in a binary counting pattern
cycle_leds_binary()