from machine import Pin, ADC
from utime import sleep
from neopixel import NeoPixel
import machine
from random import randrange
import json
print("Started!")
import time
with open("diagram.json", "r") as jFile:
data = json.load(jFile)
tmp = data["parts"][2]["attrs"]["pixels"]
NUM_LEDS = int(tmp)
leds = NeoPixel(Pin(13, Pin.OUT),NUM_LEDS)
potenci = machine.Pin(15, Pin.OUT)
adc = ADC(potenci)
times = 0
seznam = []
last = 0
def convert(x, in_max, out_max, in_min = 0, out_min = 0):
return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min
for i in range(5):
while True:
rand = randrange(0,25)
if max(rand,last) - min(rand, last) > 20:
break
seznam.append(rand )
last = rand
print(seznam)
while True:
if len(seznam) < 1:
print("your're done")
leds.fill([0, 255, 255])
leds.write()
break
leds.fill([0,0,0])
leds[seznam[0]] = [0, 255, 0]
turned= int(adc.read())
if convert(turned, 4095, NUM_LEDS -1) == seznam[0]:
print(times)
if time.time() - times > 1:
times = time.time()
seznam.pop(0)
print("you did it")
continue
else: times = time.time()
leds[convert(turned, 4095, NUM_LEDS -1)] = [255, 0, 0]
leds.write()