from machine import Pin
import time
import neopixel
NUM_LED = 16
leds = neopixel.NeoPixel(Pin(15), NUM_LED)
btn = Pin(19, Pin.IN, Pin.PULL_UP)
leds[0] = (0, 255, 0)
leds.write()
c = 0
elapsed_time = 0
button_pressed = False
ta = 0
while True:
btnVal = not bool(btn.value())
if btnVal and not button_pressed:
c = c + 1
t = time.time()-ta
print(t)
if t < 1:
leds[c] = (0, 255, 0)
elif 1 <= t < 2:
leds[c] = (0, 0, 255)
elif t >= 2:
leds[c] = (255, 0, 0)
button_pressed = True
start_time = 0
leds.write()
elif not btnVal:
button_pressed = False
time.sleep(0.01)