30
30
* Author(s): Damien P. George, Scott Shawcroft, Carter Nelson, Roy Hooper
31
31
"""
32
32
33
+ # pylint: disable=ungrouped-imports
34
+ import sys
33
35
import digitalio
34
36
from neopixel_write import neopixel_write
35
- try :
36
- import _pixelbuf
37
- except ImportError :
37
+
38
+ if sys .implementation .version [0 ] < 5 :
38
39
import adafruit_pypixelbuf as _pixelbuf
40
+ else :
41
+ try :
42
+ import _pixelbuf
43
+ except ImportError :
44
+ import adafruit_pypixelbuf as _pixelbuf
39
45
40
46
41
47
__version__ = "0.0.0-auto.0"
42
48
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel.git"
43
49
44
50
45
51
# Pixel color order constants
46
- RGB = ' RGB'
52
+ RGB = " RGB"
47
53
"""Red Green Blue"""
48
- GRB = ' GRB'
54
+ GRB = " GRB"
49
55
"""Green Red Blue"""
50
- RGBW = ' RGBW'
56
+ RGBW = " RGBW"
51
57
"""Red Green Blue White"""
52
- GRBW = ' GRBW'
58
+ GRBW = " GRBW"
53
59
"""Green Red Blue White"""
54
60
55
61
@@ -111,25 +117,20 @@ class NeoPixel(_pixelbuf.PixelBuf):
111
117
Overall brightness of the pixel (0 to 1.0)
112
118
113
119
"""
114
- bpp = None
115
- n = 0
116
-
117
- def __init__ (self , pin , n , * , bpp = 3 , brightness = 1.0 , auto_write = True , pixel_order = None ):
118
- self .bpp = bpp
119
- self .n = n
120
120
121
+ def __init__ (
122
+ self , pin , n , * , bpp = 3 , brightness = 1.0 , auto_write = True , pixel_order = None
123
+ ):
121
124
if not pixel_order :
122
125
pixel_order = GRB if bpp == 3 else GRBW
123
126
else :
124
- self .bpp = bpp = len (pixel_order )
125
127
if isinstance (pixel_order , tuple ):
126
- order_chars = RGBW
127
- order = []
128
- for char_no , order in enumerate (pixel_order ):
129
- order [pixel_order ] = order_chars [char_no ]
130
- pixel_order = '' .join (order )
128
+ order_list = [RGBW [order ] for order in pixel_order ]
129
+ pixel_order = "" .join (order_list )
131
130
132
- super ().__init__ (n , brightness = brightness , byteorder = pixel_order , auto_write = auto_write )
131
+ super ().__init__ (
132
+ n , brightness = brightness , byteorder = pixel_order , auto_write = auto_write
133
+ )
133
134
134
135
self .pin = digitalio .DigitalInOut (pin )
135
136
self .pin .direction = digitalio .Direction .OUTPUT
@@ -149,6 +150,13 @@ def __exit__(self, exception_type, exception_value, traceback):
149
150
def __repr__ (self ):
150
151
return "[" + ", " .join ([str (x ) for x in self ]) + "]"
151
152
153
+ @property
154
+ def n (self ):
155
+ """
156
+ The number of neopixels in the chain (read-only)
157
+ """
158
+ return len (self )
159
+
152
160
def write (self ):
153
161
""".. deprecated: 1.0.0
154
162
0 commit comments