import time, neopixel
from machine import Pin
leds = neopixel.NeoPixel(Pin(18), 16)
# Button setup
button = Pin(4, Pin.IN, Pin.PULL_UP) # Pin for connecting the button
last_click_time = 0
prev_click_time = 0
button_pressed = False
leds[0] = (0, 255, 0)
leds.write()
curr = 1
while True:
if not button.value():
if not button_pressed: # preverimo če je gumb pritisnjen
# ta del, da preprečimo držanje gumba
button_pressed = True # postavimo pritisnjeno na True
current_time = time.time_ns()
if current_time - last_click_time < 1000000000:
current_color = (0, 255, 0)
elif current_time - prev_click_time < 2000000000:
current_color = (0, 0, 255)
else:
current_color = (255, 0, 0)
leds[curr] = current_color
leds.write()
curr += 1
curr %= 16 # da lahko krožimo
prev_click_time = last_click_time
last_click_time = current_time
else:
button_pressed = False # če pridemo v else, damo pritisnjeno na False