fixed some mistakes in comments

pull/3/head
blaz-r 2021-04-12 16:41:24 +02:00
rodzic cb63346324
commit 77e21be074
3 zmienionych plików z 9 dodań i 7 usunięć

Wyświetl plik

@ -13,7 +13,7 @@ from neopixel import Neopixel
pixels = Neopixel(10, 0, 0, "RGBW")
```
Mind that you can use whichever order of RGB / RGBW you want (GRB, WRGB, GRB, RGWB ...). This only represents order of data sent to led-strip, all functions still work with RGBW order. Exact order of leds should be on package of your led-strip. (My BTF-lights sk6812 has GRBW)
Mind that you can use whichever order of RGB / RGBW you want (GRB, WRGB, GRB, RGWB ...). This only represents order of data sent to led-strip, all functions still work with RGBW order. Exact order of leds should be on package of your led-strip. (My BTF-lights sk6812 has GRBW).
This class has many methods, two main ones being show() which sends the data to the strip, and set_pixel which sets the color values for a particular LED. The parameters are LED number and a tuple of form (red, green blue) or (red, green, blue, white) with the colors taking values between 0 and 255.

Wyświetl plik

@ -6,6 +6,7 @@ from neopixel import Neopixel
numpix = 60
strip = Neopixel(numpix, 1, 1, "GRB")
# strip = Neopixel(numpix, 0, 0, "GRBW")
red = (255, 0, 0)
orange = (255, 50, 0)

Wyświetl plik

@ -47,12 +47,13 @@ def sk6812():
# Same hold for every other index (and - 1 at the end for 3 letter strings).
class Neopixel:
def __init__(self, num_leds, state_machine, pin, mode="RGB", delay=0.001):
def __init__(self, num_leds, state_machine, pin, mode="RGB", delay=0.0001):
self.pixels = array.array("I", [0 for _ in range(num_leds)])
self.mode = set(mode) # set for better performance
self.mode = set(mode) # set for better performance
if 'W' in self.mode:
# RGBW uses different PIO state machine configuration
self.sm = rp2.StateMachine(state_machine, sk6812, freq=8000000, sideset_base=Pin(pin))
# dictionary of values required to shift bit into position (check class desc.)
self.shift = {'R': (mode.index('R') ^ 3) * 8, 'G': (mode.index('G') ^ 3) * 8,
'B': (mode.index('B') ^ 3) * 8, 'W': (mode.index('W') ^ 3) * 8}
else:
@ -69,9 +70,9 @@ class Neopixel:
if brightness == None:
return self.brightnessvalue
else:
if (brightness < 1):
if brightness < 1:
brightness = 1
if (brightness > 255):
if brightness > 255:
brightness = 255
self.brightnessvalue = brightness
@ -102,7 +103,7 @@ class Neopixel:
self.set_pixel(i, rgb_w)
# Set red, green and blue value of pixel on position <pixel_num>
# Function accepts (r, g, b) tuple or individual rgb values3
# Function accepts (r, g, b) / (r, g, b, w) tuple
def set_pixel(self, pixel_num, rgb_w):
pos = self.shift
@ -131,7 +132,7 @@ class Neopixel:
# Update pixels
def show(self):
# if we use only RGB, we cut 8 bits of, otherwise we keep all 32
# If mode is RGB, we cut 8 bits of, otherwise we keep all 32
cut = 8
if 'W' in self.mode:
cut = 0