from machine import Pin, ADC
import neopixel
import time
from time import sleep
import random
NUM_LED = 50
potPin = 12
leds = neopixel.NeoPixel(Pin(5), NUM_LED)
pot = ADC(Pin(potPin))
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
while True:
start = time.time_ns()
for i in range(5):
a = random.randint(0, 50)
leds[a] = [0,250,0]
leds.write()
p = convert(pot.read(),0,4096,0,NUM_LED)
while p != a:
leds[p] = [250,0,0]
leds.write()
print(p)
p = convert(pot.read(),0,4096,0,NUM_LED)
leds.fill([0,0,0])
leds[a] = [0,250,0]
leds.write()
finish = time.time_ns()
time1 = round(((finish+start)/1000000000),2)
print(f"{time1}s")
sleep(5)