34
34
import board
35
35
import adafruit_dotstar as dotstar
36
36
37
- class PixelDisplayFeatherWing :
38
- """Base Class for DotStar and NeoPixel FeatherWings
37
+ class DotStarFeatherWing :
38
+ """Class representing a `DotStar FeatherWing
39
+ <https://www.adafruit.com/product/3449>`_.
39
40
40
41
The feather uses pins D13 and D11"""
41
- def __init__ (self ):
42
- self .rows = 0
43
- self .columns = 0
44
- self ._display = None
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
45
50
self ._auto_write = True
51
+ self ._display = dotstar .DotStar (clock , data , self .rows * self .columns ,
52
+ brightness = brightness , auto_write = False )
46
53
47
54
def __setitem__ (self , indices , value ):
48
55
"""
@@ -56,9 +63,8 @@ def __setitem__(self, indices, value):
56
63
a single, longer int that contains RGB values, like 0xFFFFFF
57
64
brightness, if specified should be a float 0-1
58
65
"""
59
- if self ._display is not None :
60
- self ._display [self ._get_index (indices )] = value
61
- self ._update ()
66
+ self ._display [self ._get_index (indices )] = value
67
+ self ._update ()
62
68
63
69
def __getitem__ (self , indices ):
64
70
"""
@@ -67,10 +73,7 @@ def __getitem__(self, indices):
67
73
a slice of DotStar indexes to retrieve
68
74
a single int that specifies the DotStar index
69
75
"""
70
- if self ._display is not None :
71
- return self ._display [self ._get_index (indices )]
72
- else :
73
- return None
76
+ return self ._display [self ._get_index (indices )]
74
77
75
78
def _get_index (self , indices ):
76
79
"""
@@ -92,88 +95,6 @@ def _get_index(self, indices):
92
95
else :
93
96
raise ValueError ('Index must be 1 or 2 number' )
94
97
95
- def _update (self ):
96
- """
97
- Update the Display automatically if auto_write is set to True
98
- """
99
- if self ._auto_write :
100
- self ._display .show ()
101
-
102
- def _fill (self , color = 0 ):
103
- """
104
- Fills all of the Pixels with a color or unlit if empty.
105
- """
106
- self ._display .fill (color )
107
- self ._update ()
108
-
109
- def _show (self ):
110
- """
111
- Update the Pixels. This is only needed if auto_write is set to False
112
- This can be very useful for more advanced graphics effects.
113
- """
114
- self ._display .show ()
115
-
116
- def _shift_right (self , rotate = False ):
117
- """
118
- Shift all pixels right
119
- """
120
- for y in range (0 , self .rows ):
121
- last_pixel = self ._display [(y + 1 ) * self .columns - 1 ] if rotate else 0
122
- for x in range (self .columns - 1 , 0 , - 1 ):
123
- self ._display [y * self .columns + x ] = self ._display [y * self .columns + x - 1 ]
124
- self ._display [y * self .columns ] = last_pixel
125
- self ._update ()
126
-
127
- def _shift_left (self , rotate = False ):
128
- """
129
- Shift all pixels left
130
- """
131
- for y in range (0 , self .rows ):
132
- last_pixel = self ._display [y * self .columns ] if rotate else 0
133
- for x in range (0 , self .columns - 1 ):
134
- self ._display [y * self .columns + x ] = self ._display [y * self .columns + x + 1 ]
135
- self ._display [(y + 1 ) * self .columns - 1 ] = last_pixel
136
- self ._update ()
137
-
138
- def _shift_up (self , rotate = False ):
139
- """
140
- Shift all pixels up
141
- """
142
- for x in range (0 , self .columns ):
143
- last_pixel = self ._display [(self .rows - 1 ) * self .columns + x ] if rotate else 0
144
- for y in range (self .rows - 1 , 0 , - 1 ):
145
- self ._display [y * self .columns + x ] = self ._display [(y - 1 ) * self .columns + x ]
146
- self ._display [x ] = last_pixel
147
- self ._update ()
148
-
149
- def _shift_down (self , rotate = False ):
150
- """
151
- Shift all pixels down
152
- """
153
- for x in range (0 , self .columns ):
154
- last_pixel = self ._display [x ] if rotate else 0
155
- for y in range (0 , self .rows - 1 ):
156
- self ._display [y * self .columns + x ] = self ._display [(y + 1 ) * self .columns + x ]
157
- self ._display [(self .rows - 1 ) * self .columns + x ] = last_pixel
158
- self ._update ()
159
-
160
- class DotStarFeatherWing (PixelDisplayFeatherWing ):
161
- """Class representing a `DotStar FeatherWing
162
- <https://www.adafruit.com/product/3449>`_.
163
-
164
- The feather uses pins D13 and D11"""
165
- def __init__ (self , clock = board .D13 , data = board .D11 , brightness = 0.2 ):
166
- """
167
- :param pin clock: The clock pin for the featherwing
168
- :param pin data: The data pin for the featherwing
169
- :param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
170
- """
171
- super ().__init__ ()
172
- self .rows = 6
173
- self .columns = 12
174
- self ._display = dotstar .DotStar (clock , data , self .rows * self .columns ,
175
- brightness = brightness , auto_write = False )
176
-
177
98
def fill (self , color = 0 ):
178
99
"""
179
100
Fills all of the DotStars with a color or unlit if empty.
@@ -198,7 +119,8 @@ def fill(self, color=0):
198
119
dotstar.fill() # Clear all lit DotStars
199
120
200
121
"""
201
- super ()._fill (color )
122
+ self ._display .fill (color )
123
+ self ._update ()
202
124
203
125
def show (self ):
204
126
"""
@@ -220,7 +142,7 @@ def show(self):
220
142
dotstar.show() # Update the DotStars
221
143
222
144
"""
223
- super (). _show ()
145
+ self . _display . show ()
224
146
225
147
def shift_right (self , rotate = False ):
226
148
"""
@@ -253,7 +175,12 @@ def shift_right(self, rotate=False):
253
175
time.sleep(.1)
254
176
255
177
"""
256
- super ()._shift_right (rotate )
178
+ for y in range (0 , self .rows ):
179
+ last_pixel = self ._display [(y + 1 ) * self .columns - 1 ] if rotate else 0
180
+ for x in range (self .columns - 1 , 0 , - 1 ):
181
+ self ._display [y * self .columns + x ] = self ._display [y * self .columns + x - 1 ]
182
+ self ._display [y * self .columns ] = last_pixel
183
+ self ._update ()
257
184
258
185
def shift_left (self , rotate = False ):
259
186
"""
@@ -286,7 +213,12 @@ def shift_left(self, rotate=False):
286
213
time.sleep(.1)
287
214
288
215
"""
289
- super ()._shift_left (rotate )
216
+ for y in range (0 , self .rows ):
217
+ last_pixel = self ._display [y * self .columns ] if rotate else 0
218
+ for x in range (0 , self .columns - 1 ):
219
+ self ._display [y * self .columns + x ] = self ._display [y * self .columns + x + 1 ]
220
+ self ._display [(y + 1 ) * self .columns - 1 ] = last_pixel
221
+ self ._update ()
290
222
291
223
def shift_up (self , rotate = False ):
292
224
"""
@@ -319,7 +251,12 @@ def shift_up(self, rotate=False):
319
251
time.sleep(.1)
320
252
321
253
"""
322
- super ()._shift_up (rotate )
254
+ for x in range (0 , self .columns ):
255
+ last_pixel = self ._display [(self .rows - 1 ) * self .columns + x ] if rotate else 0
256
+ for y in range (self .rows - 1 , 0 , - 1 ):
257
+ self ._display [y * self .columns + x ] = self ._display [(y - 1 ) * self .columns + x ]
258
+ self ._display [x ] = last_pixel
259
+ self ._update ()
323
260
324
261
def shift_down (self , rotate = False ):
325
262
"""
@@ -352,7 +289,19 @@ def shift_down(self, rotate=False):
352
289
time.sleep(.1)
353
290
354
291
"""
355
- super ()._shift_down (rotate )
292
+ for x in range (0 , self .columns ):
293
+ last_pixel = self ._display [x ] if rotate else 0
294
+ for y in range (0 , self .rows - 1 ):
295
+ self ._display [y * self .columns + x ] = self ._display [(y + 1 ) * self .columns + x ]
296
+ self ._display [(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 ._display .show ()
356
305
357
306
@property
358
307
def auto_write (self ):
0 commit comments