from machine import Pin, ADC
import neopixel
import time
from time import sleep
import random
import utime
NUM_LED = 50
potPin = 2
leds = neopixel.NeoPixel(Pin(15), NUM_LED)
pot = ADC(Pin(potPin))
st = 0
def convert(x, in_min, in_max, out_min, out_max):
return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
start = time.time()
for i in range(5):
a = random.randint(1, 50)
leds.fill([0,0,0])
leds[a] = [0,250,0]
leds.write()
poten = convert(pot.read(),0,4096,0,NUM_LED)
time1 = 0
time2 = 0
while (time2-time1) <= 0.5:
time1 = time.time()
st += 1
a = random.randint(1, 50)
while poten != a:
leds[poten] = [250,0,0]
leds.write()
print(poten)
poten = convert(pot.read(),0,4096,0,NUM_LED)
leds.fill([0,0,0])
leds[a] = [0,250,0]
leds.write()
time2 = time.time()
finish = time.time()
print("Čas: ", end ="")
print(finish-start,end="")
print("s")
print("Število ponovitev", end="")
print(st)