from machine import Pin
import time
led_pins = [2, 4, 5] # Define GPIO pins for 3 LEDs using a list
button_pin = 0 # Define button GPIO pin
leds = [Pin(pin, Pin.OUT) for pin in led_pins] # Initialize LEDs
button = Pin(button_pin, Pin.IN, Pin.PULL_UP)
led_index = 0 # To track which LED to toggle
while True:
if button.value() == 0: # Button pressed (active low)
leds[led_index].on() # Turn on the current LED
time.sleep(0.5) # Keep the LED on for a short period
leds[led_index].off() # Turn off the current LED
led_index = (led_index + 1) % len(leds) # Move to the next LED
time.sleep(0.5) # Debounce delay
time.sleep(0.1) # Short delay to prevent rapid button reading