33
33
34
34
import board
35
35
import adafruit_dotstar as dotstar
36
+ #pylint: disable-msg=unsubscriptable-object, unsupported-assignment-operation
36
37
37
- class DotStarFeatherWing :
38
- """Class representing a `DotStar FeatherWing
39
- <https://www.adafruit.com/product/3449>`_.
38
+ class PixelMatrixFeatherWing :
39
+ """Base Class for DotStar and NeoPixel FeatherWings
40
40
41
41
The feather uses pins D13 and D11"""
42
- def __init__ (self , clock = board .D13 , data = board .D11 , brightness = 0.2 ):
43
- """
44
- :param pin clock: The clock pin for the featherwing
45
- :param pin data: The data pin for the featherwing
46
- :param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
47
- """
48
- self .rows = 6
49
- self .columns = 12
42
+ def __init__ (self ):
43
+ self .rows = 0
44
+ self .columns = 0
45
+ self ._matrix = None
50
46
self ._auto_write = True
51
- self ._matrix = dotstar .DotStar (clock , data , self .rows * self .columns ,
52
- brightness = brightness , auto_write = False )
53
47
54
48
def __setitem__ (self , indices , value ):
55
49
"""
@@ -95,6 +89,88 @@ def _get_index(self, indices):
95
89
else :
96
90
raise ValueError ('Index must be 1 or 2 number' )
97
91
92
+ def _update (self ):
93
+ """
94
+ Update the Display automatically if auto_write is set to True
95
+ """
96
+ if self ._auto_write :
97
+ self ._matrix .show ()
98
+
99
+ def _fill (self , color = 0 ):
100
+ """
101
+ Fills all of the Pixels with a color or unlit if empty.
102
+ """
103
+ self ._matrix .fill (color )
104
+ self ._update ()
105
+
106
+ def _show (self ):
107
+ """
108
+ Update the Pixels. This is only needed if auto_write is set to False
109
+ This can be very useful for more advanced graphics effects.
110
+ """
111
+ self ._matrix .show ()
112
+
113
+ def _shift_right (self , rotate = False ):
114
+ """
115
+ Shift all pixels right
116
+ """
117
+ for y in range (0 , self .rows ):
118
+ last_pixel = self ._matrix [(y + 1 ) * self .columns - 1 ] if rotate else 0
119
+ for x in range (self .columns - 1 , 0 , - 1 ):
120
+ self ._matrix [y * self .columns + x ] = self ._matrix [y * self .columns + x - 1 ]
121
+ self ._matrix [y * self .columns ] = last_pixel
122
+ self ._update ()
123
+
124
+ def _shift_left (self , rotate = False ):
125
+ """
126
+ Shift all pixels left
127
+ """
128
+ for y in range (0 , self .rows ):
129
+ last_pixel = self ._matrix [y * self .columns ] if rotate else 0
130
+ for x in range (0 , self .columns - 1 ):
131
+ self ._matrix [y * self .columns + x ] = self ._matrix [y * self .columns + x + 1 ]
132
+ self ._matrix [(y + 1 ) * self .columns - 1 ] = last_pixel
133
+ self ._update ()
134
+
135
+ def _shift_up (self , rotate = False ):
136
+ """
137
+ Shift all pixels up
138
+ """
139
+ for x in range (0 , self .columns ):
140
+ last_pixel = self ._matrix [(self .rows - 1 ) * self .columns + x ] if rotate else 0
141
+ for y in range (self .rows - 1 , 0 , - 1 ):
142
+ self ._matrix [y * self .columns + x ] = self ._matrix [(y - 1 ) * self .columns + x ]
143
+ self ._matrix [x ] = last_pixel
144
+ self ._update ()
145
+
146
+ def _shift_down (self , rotate = False ):
147
+ """
148
+ Shift all pixels down
149
+ """
150
+ for x in range (0 , self .columns ):
151
+ last_pixel = self ._matrix [x ] if rotate else 0
152
+ for y in range (0 , self .rows - 1 ):
153
+ self ._matrix [y * self .columns + x ] = self ._matrix [(y + 1 ) * self .columns + x ]
154
+ self ._matrix [(self .rows - 1 ) * self .columns + x ] = last_pixel
155
+ self ._update ()
156
+
157
+ class DotStarFeatherWing (PixelMatrixFeatherWing ):
158
+ """Class representing a `DotStar FeatherWing
159
+ <https://www.adafruit.com/product/3449>`_.
160
+
161
+ The feather uses pins D13 and D11"""
162
+ def __init__ (self , clock = board .D13 , data = board .D11 , brightness = 0.2 ):
163
+ """
164
+ :param pin clock: The clock pin for the featherwing
165
+ :param pin data: The data pin for the featherwing
166
+ :param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
167
+ """
168
+ super ().__init__ ()
169
+ self .rows = 6
170
+ self .columns = 12
171
+ self ._matrix = dotstar .DotStar (clock , data , self .rows * self .columns ,
172
+ brightness = brightness , auto_write = False )
173
+
98
174
def fill (self , color = 0 ):
99
175
"""
100
176
Fills all of the DotStars with a color or unlit if empty.
@@ -119,8 +195,7 @@ def fill(self, color=0):
119
195
dotstar.fill() # Clear all lit DotStars
120
196
121
197
"""
122
- self ._matrix .fill (color )
123
- self ._update ()
198
+ super ()._fill (color )
124
199
125
200
def show (self ):
126
201
"""
@@ -142,7 +217,7 @@ def show(self):
142
217
dotstar.show() # Update the DotStars
143
218
144
219
"""
145
- self . _matrix . show ()
220
+ super (). _show ()
146
221
147
222
def shift_right (self , rotate = False ):
148
223
"""
@@ -175,12 +250,7 @@ def shift_right(self, rotate=False):
175
250
time.sleep(.1)
176
251
177
252
"""
178
- for y in range (0 , self .rows ):
179
- last_pixel = self ._matrix [(y + 1 ) * self .columns - 1 ] if rotate else 0
180
- for x in range (self .columns - 1 , 0 , - 1 ):
181
- self ._matrix [y * self .columns + x ] = self ._matrix [y * self .columns + x - 1 ]
182
- self ._matrix [y * self .columns ] = last_pixel
183
- self ._update ()
253
+ super ()._shift_right (rotate )
184
254
185
255
def shift_left (self , rotate = False ):
186
256
"""
@@ -213,12 +283,7 @@ def shift_left(self, rotate=False):
213
283
time.sleep(.1)
214
284
215
285
"""
216
- for y in range (0 , self .rows ):
217
- last_pixel = self ._matrix [y * self .columns ] if rotate else 0
218
- for x in range (0 , self .columns - 1 ):
219
- self ._matrix [y * self .columns + x ] = self ._matrix [y * self .columns + x + 1 ]
220
- self ._matrix [(y + 1 ) * self .columns - 1 ] = last_pixel
221
- self ._update ()
286
+ super ()._shift_left (rotate )
222
287
223
288
def shift_up (self , rotate = False ):
224
289
"""
@@ -251,12 +316,7 @@ def shift_up(self, rotate=False):
251
316
time.sleep(.1)
252
317
253
318
"""
254
- for x in range (0 , self .columns ):
255
- last_pixel = self ._matrix [(self .rows - 1 ) * self .columns + x ] if rotate else 0
256
- for y in range (self .rows - 1 , 0 , - 1 ):
257
- self ._matrix [y * self .columns + x ] = self ._matrix [(y - 1 ) * self .columns + x ]
258
- self ._matrix [x ] = last_pixel
259
- self ._update ()
319
+ super ()._shift_up (rotate )
260
320
261
321
def shift_down (self , rotate = False ):
262
322
"""
@@ -289,19 +349,7 @@ def shift_down(self, rotate=False):
289
349
time.sleep(.1)
290
350
291
351
"""
292
- for x in range (0 , self .columns ):
293
- last_pixel = self ._matrix [x ] if rotate else 0
294
- for y in range (0 , self .rows - 1 ):
295
- self ._matrix [y * self .columns + x ] = self ._matrix [(y + 1 ) * self .columns + x ]
296
- self ._matrix [(self .rows - 1 ) * self .columns + x ] = last_pixel
297
- self ._update ()
298
-
299
- def _update (self ):
300
- """
301
- Update the Display automatically if auto_write is set to True
302
- """
303
- if self ._auto_write :
304
- self ._matrix .show ()
352
+ super ()._shift_down (rotate )
305
353
306
354
@property
307
355
def auto_write (self ):
0 commit comments