from machine import Pin, ADC
import neopixel
from time import sleep
import random
import time
NUM_LED = 16
potPin=12
leds = neopixel.NeoPixel(Pin(5), NUM_LED)
pot= ADC(Pin(12,Pin.IN))
def hitrostanimacije():
while True:
for i in range(NUM_LED):
t=pot.read()/1000
leds[i]=[0, 133, 255 ]
leds.write()
sleep(t)
leds[i]=[0,0,0]
sleep(1)
print(t)
def mocmutacije():
while True:
mutacija=int(pot.read()/100)
barva=[random.randint(0,255),random.randint(0,255),random.randint(0,255)]
print(barva)
for i in range (NUM_LED):
leds[i]=barva
leds.write()
barva=[(barva[0]+random.randint(-mutacija,mutacija))%255,(barva[1]+random.randint(-mutacija,mutacija))%255,(barva[2]+random.randint(-mutacija,mutacija))%255]
print(barva)
sleep(0.5)
def refleksigra():
gumb=Pin(21, Pin.IN, Pin.PULL_UP)
while True:
leds.fill([16, 255, 0 ])
leds.write()
sleep(random.randrange(1,5))
start = time.time_ns()
while True:
leds.fill([255, 0, 0 ])
leds.write()
if gumb.value()==0:
finish = time.time_ns()
leds.fill([0,0,0])
leds.write()
break
time1 = round(((finish-start)/1000000000),2)
print(f"{time1}s")
sleep(5)
#hitrostanimacije()
#mocmutacije()
refleksigra()