import machine, neopixel, time
from colorsys import hsv_to_rgb
from my_functions import clear_ring
np_pin = machine.Pin(22) # pin is a machine.Pin instance.
np_n = 16 # n is the number of LEDs in the strip.
np_bpp = 3 # bpp is 3 for RGB LEDs, and 4 for RGBW LEDs.
np_timing = 1 # timing is 0 for 400KHz, and 1 for 800kHz LEDs (most are 800kHz).
np_auto_write: True
np = neopixel.NeoPixel(np_pin, np_n, np_bpp, np_timing, np_auto_write)
class Led():
def __init__(self, pos, hue, sat, vib):
self.pos = pos
self.hue = hue
self.sat = sat
self.vib = vib
def clear(self):
np[self.pos] = np.bpp*(0,)
np.write()
def write(self):
np.write()
def set_color(self):
print(f"Set color: hue: {self.hue}, sat: {self.sat}, vib: {self.vib}, pos: {self.pos})
f_h=1/360
f_s=1/100
f_v=255/100
color = tuple(map(round,hsv_to_rgb(self.hue*f_h, self.sat*f_s, self.vib*f_v))) # tuple map rounded to return rgb integers
np[self.pos]= color
np.write()
def move_cw(self): # move the led clockwise
self.clear()
self.pos += 1
self.set_color()
def move_ccw(self): # move the led counter clockwise
self.clear()
self.pos -= 1
self.set_color()
clear_ring()
test = Led(1,12,100,100)
test.set_color()