import random
import neopixel
import time
from machine import Pin, ADC


Num_Leds = 20

Num_LedsL = Num_Leds
pot = ADC(Pin(15, Pin.IN))
tempDelay, stevec = 0, 0
delay = pot.read() / 2048
startDelay = -1
leds = neopixel.NeoPixel(Pin(5, Pin.OUT), Num_Leds)
R = random.randint(0, 255)
G = random.randint(0, 255)
B = random.randint(0, 255)
for i in range(Num_Leds):
  leds[i] = [255, 255, 255]
leds.write()
zacetek = time.time_ns()
while True:
  for i in range(Num_LedsL):
    if delay == startDelay:
        stevec = time.time_ns() / 1000000000
    elif delay != startDelay:
        stevec = time.time_ns() / 1000000000
    else:
        if (time.time_ns() / 1000000000) - stevec > 60:
            for i in range(Num_Leds):
                leds[i] = [0, 0, 0]
            leds.write()
            tempDelay = delay
            while delay == tempDelay:
                delay = pot.read() / 2048
            stevec = time.time_ns() / 1000000000
            startDelay = delay

    leds[i] = [R, G, B]
    R = (R + random.randint(0, 20)) % 255
    G = (G + random.randint(0, 20)) % 255
    B = (B + random.randint(0, 20)) % 255
    leds.write()
    time.sleep(delay)
    if i % 10 == 0:
        R = random.randint(0, 255)
        G = random.randint(0, 255)
        B = random.randint(0, 255)
    delay = pot.read() / 2048