@@ -54,8 +54,9 @@ def __init__(self, clock=board.D13, data=board.D11, brightness=0.2):
54
54
55
55
def __setitem__ (self , indices , value ):
56
56
"""
57
- indices can be one of two things:
57
+ indices can be one of three things:
58
58
x and y ints that are calculated to the DotStar index
59
+ a slice of DotStar indexes with a set of values that match the slice
59
60
a single int that specifies the DotStar index
60
61
value can be one of three things:
61
62
a (r,g,b) list/tuple
@@ -67,9 +68,18 @@ def __setitem__(self, indices, value):
67
68
self ._update ()
68
69
69
70
def __getitem__ (self , indices ):
71
+ """
72
+ indices can be one of three things:
73
+ x and y ints that are calculated to the DotStar index
74
+ a slice of DotStar indexes to retrieve
75
+ a single int that specifies the DotStar index
76
+ """
70
77
return self ._dotstar [self ._get_index (indices )]
71
78
72
79
def _get_index (self , indices ):
80
+ """
81
+ Figure out which DotStar to address based on what was passed in
82
+ """
73
83
if isinstance (indices , int ):
74
84
if not 0 <= indices < self .rows * self .columns :
75
85
raise ValueError ('The index of {} is out of range' .format (indices ))
@@ -139,65 +149,185 @@ def shift_right(self, rotate=False):
139
149
"""
140
150
Shift all pixels right
141
151
142
- :param rotate: (Optional) Rotate the shifted pixel to the beginning (default=False)
152
+ :param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
143
153
144
- This example shifts pixels
154
+ This example shifts 2 pixels to the right
145
155
146
156
.. code-block:: python
147
157
148
158
import time
149
159
from adafruit_featherwing import dotstar_featherwing
150
160
151
161
dotstar = dotstar_featherwing.DotStarFeatherWing()
152
- dotstar.fill() # Clear any lit Dotstars
153
- dotstar.auto_write = False
154
- dotstar[0, 0] = (255, 255, 255) # Set White
162
+
163
+ # Draw Red and Green Pixels
164
+ dotstar[5, 3] = (255, 0, 0)
165
+ dotstar[6, 3] = (0, 255, 0)
166
+
167
+ # Rotate it off the screen
168
+ for i in range(0, 11):
169
+ dotstar.shift_right(True)
170
+ time.sleep(.1)
171
+
155
172
time.sleep(1)
156
- dotstar.show() # Update the DotStars
173
+ # Shift it off the screen
174
+ for i in range(0, 11):
175
+ dotstar.shift_right()
176
+ time.sleep(.1)
157
177
158
178
"""
159
179
for y in range (0 , self .rows ):
180
+ last_pixel = self ._dotstar [(y + 1 ) * self .columns - 1 ] if rotate else 0
160
181
for x in range (self .columns - 1 , 0 , - 1 ):
161
182
self ._dotstar [y * self .columns + x ] = self ._dotstar [y * self .columns + x - 1 ]
162
- last_pixel = self ._dotstar [(y + 1 ) * self .columns - 1 ] if rotate else 0
163
183
self ._dotstar [y * self .columns ] = last_pixel
164
184
self ._update ()
165
185
166
186
def shift_left (self , rotate = False ):
167
- """Shift all pixels left"""
187
+ """
188
+ Shift all pixels left
189
+
190
+ :param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
191
+
192
+ This example shifts 2 pixels to the left
193
+
194
+ .. code-block:: python
195
+
196
+ import time
197
+ from adafruit_featherwing import dotstar_featherwing
198
+
199
+ dotstar = dotstar_featherwing.DotStarFeatherWing()
200
+
201
+ # Draw Red and Green Pixels
202
+ dotstar[5, 3] = (255, 0, 0)
203
+ dotstar[6, 3] = (0, 255, 0)
204
+
205
+ # Rotate it off the screen
206
+ for i in range(0, 11):
207
+ dotstar.shift_left(True)
208
+ time.sleep(.1)
209
+
210
+ time.sleep(1)
211
+ # Shift it off the screen
212
+ for i in range(0, 11):
213
+ dotstar.shift_left()
214
+ time.sleep(.1)
215
+
216
+ """
168
217
for y in range (0 , self .rows ):
218
+ last_pixel = self ._dotstar [y * self .columns ] if rotate else 0
169
219
for x in range (0 , self .columns - 1 ):
170
220
self ._dotstar [y * self .columns + x ] = self ._dotstar [y * self .columns + x + 1 ]
171
- last_pixel = self ._dotstar [y * self .columns ] if rotate else 0
172
221
self ._dotstar [(y + 1 ) * self .columns - 1 ] = last_pixel
173
222
self ._update ()
174
223
175
224
def shift_up (self , rotate = False ):
176
- """Shift all pixels up"""
225
+ """
226
+ Shift all pixels up
227
+
228
+ :param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
229
+
230
+ This example shifts 2 pixels up
231
+
232
+ .. code-block:: python
233
+
234
+ import time
235
+ from adafruit_featherwing import dotstar_featherwing
236
+
237
+ dotstar = dotstar_featherwing.DotStarFeatherWing()
238
+
239
+ # Draw Red and Green Pixels
240
+ dotstar[5, 3] = (255, 0, 0)
241
+ dotstar[6, 3] = (0, 255, 0)
242
+
243
+ # Rotate it off the screen
244
+ for i in range(0, 5):
245
+ dotstar.shift_up(True)
246
+ time.sleep(.1)
247
+
248
+ time.sleep(1)
249
+ # Shift it off the screen
250
+ for i in range(0, 5):
251
+ dotstar.shift_up()
252
+ time.sleep(.1)
253
+
254
+ """
177
255
for x in range (0 , self .columns ):
256
+ last_pixel = self ._dotstar [(self .rows - 1 ) * self .columns + x ] if rotate else 0
178
257
for y in range (self .rows - 1 , 0 , - 1 ):
179
258
self ._dotstar [y * self .columns + x ] = self ._dotstar [(y - 1 ) * self .columns + x ]
180
- last_pixel = self ._dotstar [(self .rows - 1 ) * self .columns + x ] if rotate else 0
181
259
self ._dotstar [x ] = last_pixel
182
260
self ._update ()
183
261
184
262
def shift_down (self , rotate = False ):
185
- """Shift all pixels down"""
263
+ """
264
+ Shift all pixels down
265
+
266
+ :param rotate: (Optional) Rotate the shifted pixels to top (default=False)
267
+
268
+ This example shifts 2 pixels down
269
+
270
+ .. code-block:: python
271
+
272
+ import time
273
+ from adafruit_featherwing import dotstar_featherwing
274
+
275
+ dotstar = dotstar_featherwing.DotStarFeatherWing()
276
+
277
+ # Draw Red and Green Pixels
278
+ dotstar[5, 3] = (255, 0, 0)
279
+ dotstar[6, 3] = (0, 255, 0)
280
+
281
+ # Rotate it off the screen
282
+ for i in range(0, 5):
283
+ dotstar.shift_down(True)
284
+ time.sleep(.1)
285
+
286
+ time.sleep(1)
287
+ # Shift it off the screen
288
+ for i in range(0, 5):
289
+ dotstar.shift_down()
290
+ time.sleep(.1)
291
+
292
+ """
186
293
for x in range (0 , self .columns ):
294
+ last_pixel = self ._dotstar [x ] if rotate else 0
187
295
for y in range (0 , self .rows - 1 ):
188
296
self ._dotstar [y * self .columns + x ] = self ._dotstar [(y + 1 ) * self .columns + x ]
189
- last_pixel = self ._dotstar [x ] if rotate else 0
190
297
self ._dotstar [(self .rows - 1 ) * self .columns + x ] = last_pixel
191
298
self ._update ()
192
299
193
300
def _update (self ):
301
+ """
302
+ Update the Display automatically if auto_write is set to True
303
+ """
194
304
if self ._auto_write :
195
305
self ._dotstar .show ()
196
306
197
307
@property
198
308
def auto_write (self ):
199
- """Whether or not we are automatically updating
200
- If set to false, be sure to call show() to update"""
309
+ """
310
+ Whether or not we are automatically updating
311
+ If set to false, be sure to call show() to update
312
+
313
+ This lights DotStars with and without auto_write
314
+
315
+ .. code-block:: python
316
+
317
+ import time
318
+ from adafruit_featherwing import dotstar_featherwing
319
+
320
+ dotstar = dotstar_featherwing.DotStarFeatherWing()
321
+ dotstar.fill() # Clear any lit Dotstars
322
+ dotstar[0, 0] = (255, 255, 255) # Set White
323
+ time.sleep(1)
324
+
325
+ dotstar.auto_write = False
326
+ dotstar[1, 0] = (255, 255, 255) # Set White
327
+ time.sleep(1)
328
+ dotstar.show() # Update the DotStars
329
+
330
+ """
201
331
return self ._auto_write
202
332
203
333
@auto_write .setter
@@ -207,9 +337,29 @@ def auto_write(self, write):
207
337
208
338
@property
209
339
def brightness (self ):
210
- """Overall brightness of the display"""
340
+ """
341
+ Overall brightness of the display
342
+
343
+ This example changes the brightness
344
+
345
+ .. code-block:: python
346
+
347
+ import time
348
+ from adafruit_featherwing import dotstar_featherwing
349
+
350
+ dotstar = dotstar_featherwing.DotStarFeatherWing()
351
+ dotstar.brightness = 0
352
+ dotstar.fill(0xFFFFFF)
353
+ for i in range(0, 6):
354
+ dotstar.brightness = (i / 10)
355
+ time.sleep(.2)
356
+
357
+ dotstar.brightness = 0.3
358
+
359
+ """
211
360
return self ._dotstar .brightness
212
361
213
362
@brightness .setter
214
363
def brightness (self , brightness ):
215
364
self ._dotstar .brightness = min (max (brightness , 0.0 ), 1.0 )
365
+ self ._update ()
0 commit comments