from machine import Pin, ADC
import machine, time
from random import randrange
from neopixel import NeoPixel
print("Started!")
st = 0.1
nl1 = 16
nl2 = 16
pressed = True
button = Pin(13, Pin.IN, Pin.PULL_UP)
leds1 = NeoPixel(Pin(22, Pin.OUT), nl1)
leds2 = NeoPixel(Pin(23, Pin.OUT), nl2)
# potenciometers already ADC converted
pot_r = ADC(Pin(4, Pin.OUT))
pot_g = ADC(Pin(0, Pin.OUT))
pot_b = ADC(Pin(2, Pin.OUT))
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
while True:
color_rand = [randrange(0,255), randrange(0,255), randrange(0,255)]
leds1.fill(color_rand)
leds1.write()
while True:
#Reads RGB colors from potentiometer
r = convert(pot_r.read(), 4096, 255)
g = convert(pot_g.read(), 4096, 255)
b = convert(pot_b.read(), 4096, 255)
if not button.value():
if pressed:
# makes the code run only once as long as the button's pressed
pressed = False
print(f"Razlika v barvi je: \n r: {color_rand[0]-r} \n g: {color_rand[1]-g} \n b: {color_rand[2]-b}")
score = abs(color_rand[0]-r)+abs(color_rand[1]-g)+abs(color_rand[2]-b)
print(score)
# not happening
if score == 0:
print("WOw YoU dId IT!!1!1!!!")
break
else:
# runs constantly when button not pressed
pressed = True
color_sel = [r, g, b]
leds2.fill(color_sel)
leds2.write()