from machine import Pin
from time import sleep
led_red = Pin(42, Pin.OUT)
led_orange = Pin(41, Pin.OUT)
led_yellow = Pin(40, Pin.OUT)
led_green = Pin(39, Pin.OUT)
led_blue = Pin(38, Pin.OUT)
leds = [led_red, led_orange, led_yellow, led_green, led_blue]
button_light = Pin(4, Pin.IN, Pin.PULL_UP)
count = -1
button_state = 1
prev_button_state = 1
def leds_off():
for led in leds:
led.value(0)
while True:
print(count)
if button_light.value() == 0:
button_state = button_light.value()
if prev_button_state != button_state:
count += 1
for index, led in enumerate(leds):
if count >= len(leds):
leds_off()
count = -1
elif count >= index:
led.value(1)
prev_button_state = button_state
else:
button_state = button_light.value()
prev_button_state = button_light.value()
sleep(0.333)