Skip to content

Commit faa40b3

Browse files
author
caternuson
committed
added pixel_order
1 parent c72d18c commit faa40b3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

neopixel.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,20 @@
3636
__version__ = "0.0.0-auto.0"
3737
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel.git"
3838

39+
# Pixel color order constants
40+
RGB = 0
41+
GRB = 1
42+
RGBW = 2
43+
GRBW = 3
44+
45+
# Pixel color order
46+
PIXEL_ORDER = {
47+
RGB: (0, 1, 2),
48+
GRB: (1, 0, 2),
49+
RGBW: (0, 1, 2, 3),
50+
GRBW: (1, 0, 2, 3),
51+
}
52+
3953
class NeoPixel:
4054
"""
4155
A sequence of neopixels.
@@ -76,12 +90,18 @@ class NeoPixel:
7690
pixels[::2] = [RED] * (len(pixels) // 2)
7791
time.sleep(2)
7892
"""
79-
ORDER = (1, 0, 2, 3)
80-
def __init__(self, pin, n, *, bpp=3, brightness=1.0, auto_write=True):
93+
#ORDER = (1, 0, 2, 3)
94+
def __init__(self, pin, n, *, bpp=3, brightness=1.0, auto_write=True, pixel_order=None):
8195
self.pin = digitalio.DigitalInOut(pin)
8296
self.pin.direction = digitalio.Direction.OUTPUT
8397
self.n = n
84-
self.bpp = bpp
98+
#self.bpp = bpp
99+
if pixel_order is None:
100+
self.ORDER = PIXEL_ORDER[GRBW]
101+
self.bpp = bpp
102+
else:
103+
self.ORDER = PIXEL_ORDER[pixel_order]
104+
self.bpp = len(self.ORDER)
85105
self.buf = bytearray(n * bpp)
86106
# Set auto_write to False temporarily so brightness setter does _not_
87107
# call show() while in __init__.

0 commit comments

Comments
 (0)