Decouple color and pixel indexing

pull/19/head
blaz-r 2024-03-31 19:46:20 +02:00
rodzic 8f158e6390
commit 89b06f4383
1 zmienionych plików z 8 dodań i 4 usunięć

Wyświetl plik

@ -234,12 +234,16 @@ class Neopixel:
set_pixel processes the slice)
:param idx: Index can either be indexing number or slice
:param rgb_w: Tuple of form (r, g, b) or (r, g, b, w) representing color to be used
:return:
:param rgb_w: Tuple (or list of tuples) of form (r, g, b) or (r, g, b, w) representing color to be used
:return: None
"""
if type(rgb_w) is list:
for i in range(self.num_leds):
self.set_pixel(i, rgb_w[i])
# set some subset, if idx is a slice:
if type(idx) is slice:
for rgb_i, pixel_i in enumerate(range(*idx.indices(self.num_leds))):
self.set_pixel(pixel_i, rgb_w[rgb_i])
else:
raise ValueError("Index must be a slice when setting multiple pixels as list")
else:
self.set_pixel(idx, rgb_w)