from machine import Pin, ADC
import time, neopixel, random
toleranca = 5
# projekt na: https://shorturl.at/blnF9
leds = neopixel.NeoPixel(Pin(27), 16)
leds2 = neopixel.NeoPixel(Pin(25), 16)
r1 = random.randint(0,255)
g1 = random.randint(0,255)
b1 = random.randint(0,255)
print(r1,g1,b1)
leds2.fill([r1,g1,b1])
leds2.write()
# definicija potentiometer pina
pot1 = Pin(2, Pin.IN)
pot2 = Pin(4, Pin.IN)
pot3 = Pin(15, Pin.IN)
# povežemo pin na ADC - beremo analogni signal
potR = ADC(pot1)
potG = ADC(pot2)
potB = ADC(pot3)
#nova
g = Pin(23, Pin.IN, Pin.PULL_UP )

while True:
    #nova
    vrednost = not bool(g.value())

    r2 = potR.read() // 16
    g2 = potG.read() // 16
    b2 = potB.read() // 16
    leds.fill([r2, g2, b2])
    leds.write()
    rr = abs(r1 - r2)
    rg = abs(g1 - g2)
    rb = abs(b1 - b2)
    #if  rr < toleranca and rg < toleranca and rb < toleranca:
    #nova
    if  vrednost == True:
        print( (256*3), (256*3) - (rr+rb+rg)) 
        break
    time.sleep(0.2)
    # print(abs(r1-r2), abs..)
    # če je R1 == R2 in G1 == G2 in B1 == B2... izpiši konec igre
    # če je rr < 5 in rz < 5 in rb <b
    # break - ustavi zanko v kateri se nahaja
    

# naloga
# poveži 3 "slide potentiometre"
# vsak potenciometer predstavja eno od RGB komponent
# Neopixel Krog, naj odraža barvo izbrano iz potenciometrov
# 1.pot = 255, 2. pot = 0, 3. pot = 0, krog sveti rdeče
# 0 - 4095 ... 0- 255 ... max RGB vrednost
# leds.... leds.fill([255, 0, 0]).. ne pozabi leds.write()