kopia lustrzana https://github.com/blaz-r/pi_pico_neopixel
Add array/list-like methods
rodzic
8012e3b6a6
commit
9e956e518d
11
neopixel.py
11
neopixel.py
|
@ -229,6 +229,7 @@ class Neopixel:
|
||||||
npix[15:21] = (255,0,0) # <- sets 16,17 .. 20 to red
|
npix[15:21] = (255,0,0) # <- sets 16,17 .. 20 to red
|
||||||
npix[21:29:2] = (0,0,255) # <- sets 21,23,25,27 to blue
|
npix[21:29:2] = (0,0,255) # <- sets 21,23,25,27 to blue
|
||||||
npix[1::2] = (0,0,0) # <- sets all odd pixels to 'off'
|
npix[1::2] = (0,0,0) # <- sets all odd pixels to 'off'
|
||||||
|
npix[:] = [(0,5,0),(0,5,0)] # <- replaces all pixels with those from the array
|
||||||
(the 'slice' cases pass idx as a 'slice' object, and
|
(the 'slice' cases pass idx as a 'slice' object, and
|
||||||
set_pixel processes the slice)
|
set_pixel processes the slice)
|
||||||
|
|
||||||
|
@ -236,8 +237,18 @@ class Neopixel:
|
||||||
:param rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used
|
:param rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
if type(rgb_w) is list:
|
||||||
|
for i in range(self.num_leds):
|
||||||
|
self.set_pixel(i, rgb_w[i])
|
||||||
|
else:
|
||||||
self.set_pixel(idx, rgb_w)
|
self.set_pixel(idx, rgb_w)
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return self.num_leds
|
||||||
|
|
||||||
|
def __getitem__(self, idx):
|
||||||
|
return self.get_pixel(idx)
|
||||||
|
|
||||||
def colorHSV(self, hue, sat, val):
|
def colorHSV(self, hue, sat, val):
|
||||||
"""
|
"""
|
||||||
Converts HSV color to rgb tuple and returns it.
|
Converts HSV color to rgb tuple and returns it.
|
||||||
|
|
Ładowanie…
Reference in New Issue