import machine
import time
import random
# Define GPIO pins for the LEDs
led_pins = [17, 18, 22, 27, 26] # GPIO pins for LEDs (adjust as needed)
# Set up each LED pin as an output
leds = []
for pin in led_pins:
led = machine.Pin(pin, machine.Pin.OUT)
leds.append(led)
# Function to turn on a random LED
def light_up_random_led():
led = random.choice(leds)
led.value(1) # Turn on the selected LED
# Function to turn off all LEDs
def turn_off_all_leds():
for led in leds:
led.value(0) # Turn off all LEDs
# Main loop: random blinking of LEDs
try:
while True:
# Randomly choose to light up one LED
light_up_random_led()
# Wait for a random time between 0.2 and 1 second
time.sleep(random.uniform(0.2, .6))
# Turn off all LEDs
turn_off_all_leds()
# Wait before next random blink
time.sleep(random.uniform(0.2, .6))
except KeyboardInterrupt:
print("Program stopped by user.")