Skip to content

Commit 6e83321

Browse files
author
Melissa LeBlanc-Williams
authored
Merge pull request #25 from makermelissa/master
Added NeoPixel FeatherWing
2 parents f9f0d73 + dd7dc3f commit 6e83321

12 files changed

+446
-321
lines changed

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ These drivers depends on:
2626
* `Seesaw <https://github.com/adafruit/Adafruit_CircuitPython_seesaw>`_
2727
* `HT16K33 <https://github.com/adafruit/Adafruit_CircuitPython_HT16K33>`_
2828
* `DotStar <https://github.com/adafruit/Adafruit_CircuitPython_DotStar>`_
29+
* `NeoPixel <https://github.com/adafruit/Adafruit_CircuitPython_NeoPixel>`_
2930

3031
Please ensure all dependencies are available on the CircuitPython filesystem.
3132
This is easily achieved by downloading

adafruit_featherwing/dotstar_featherwing.py

Lines changed: 5 additions & 316 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@
3333

3434
import board
3535
import adafruit_dotstar as dotstar
36+
from adafruit_featherwing.pixelmatrix import PixelMatrix
3637

37-
class DotStarFeatherWing:
38+
class DotStarFeatherWing(PixelMatrix):
3839
"""Class representing a `DotStar FeatherWing
3940
<https://www.adafruit.com/product/3449>`_.
4041
@@ -45,320 +46,8 @@ def __init__(self, clock=board.D13, data=board.D11, brightness=0.2):
4546
:param pin data: The data pin for the featherwing
4647
:param float brightness: Optional brightness (0.0-1.0) that defaults to 1.0
4748
"""
49+
super().__init__()
4850
self.rows = 6
4951
self.columns = 12
50-
self._auto_write = True
51-
self._dotstar = dotstar.DotStar(clock, data, self.rows * self.columns,
52-
brightness=brightness, auto_write=False)
53-
54-
def __setitem__(self, indices, value):
55-
"""
56-
indices can be one of three things:
57-
x and y ints that are calculated to the DotStar index
58-
a slice of DotStar indexes with a set of values that match the slice
59-
a single int that specifies the DotStar index
60-
value can be one of three things:
61-
a (r,g,b) list/tuple
62-
a (r,g,b, brightness) list/tuple
63-
a single, longer int that contains RGB values, like 0xFFFFFF
64-
brightness, if specified should be a float 0-1
65-
"""
66-
self._dotstar[self._get_index(indices)] = value
67-
self._update()
68-
69-
def __getitem__(self, indices):
70-
"""
71-
indices can be one of three things:
72-
x and y ints that are calculated to the DotStar index
73-
a slice of DotStar indexes to retrieve
74-
a single int that specifies the DotStar index
75-
"""
76-
return self._dotstar[self._get_index(indices)]
77-
78-
def _get_index(self, indices):
79-
"""
80-
Figure out which DotStar to address based on what was passed in
81-
"""
82-
if isinstance(indices, int):
83-
if not 0 <= indices < self.rows * self.columns:
84-
raise ValueError('The index of {} is out of range'.format(indices))
85-
return indices
86-
elif isinstance(indices, slice):
87-
return indices
88-
elif len(indices) == 2:
89-
x, y = indices
90-
if not 0 <= x < self.columns:
91-
raise ValueError('The X value of {} is out of range'.format(x))
92-
if not 0 <= y < self.rows:
93-
raise ValueError('The Y value of {} is out of range'.format(y))
94-
return y * self.columns + x
95-
else:
96-
raise ValueError('Index must be 1 or 2 number')
97-
98-
def fill(self, color=0):
99-
"""
100-
Fills all of the DotStars with a color or unlit if empty.
101-
102-
:param color: (Optional) The text or number to display (default=0)
103-
:type color: list/tuple or int
104-
105-
This example shows various ways of using the fill() function
106-
107-
.. code-block:: python
108-
109-
import time
110-
from adafruit_featherwing import dotstar_featherwing
111-
112-
dotstar = dotstar_featherwing.DotStarFeatherWing()
113-
dotstar.fill((255, 255, 255)) # Fill White
114-
time.sleep(1)
115-
dotstar.fill((255, 255, 255, 0.5)) # Fill White Half Brightness
116-
time.sleep(1)
117-
dotstar.fill(0xFF0000) # Fill Red
118-
time.sleep(1)
119-
dotstar.fill() # Clear all lit DotStars
120-
121-
"""
122-
self._dotstar.fill(color)
123-
self._update()
124-
125-
def show(self):
126-
"""
127-
Update the DotStars. This is only needed if auto_write is set to False
128-
This can be very useful for more advanced graphics effects.
129-
130-
This example changes the blink rate and prints out the current setting
131-
132-
.. code-block:: python
133-
134-
import time
135-
from adafruit_featherwing import dotstar_featherwing
136-
137-
dotstar = dotstar_featherwing.DotStarFeatherWing()
138-
dotstar.fill() # Clear any lit Dotstars
139-
dotstar.auto_write = False
140-
dotstar[0, 0] = (255, 255, 255) # Set White
141-
time.sleep(1)
142-
dotstar.show() # Update the DotStars
143-
144-
"""
145-
self._dotstar.show()
146-
147-
def shift_right(self, rotate=False):
148-
"""
149-
Shift all pixels right
150-
151-
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
152-
153-
This example shifts 2 pixels to the right
154-
155-
.. code-block:: python
156-
157-
import time
158-
from adafruit_featherwing import dotstar_featherwing
159-
160-
dotstar = dotstar_featherwing.DotStarFeatherWing()
161-
162-
# Draw Red and Green Pixels
163-
dotstar[5, 3] = (255, 0, 0)
164-
dotstar[6, 3] = (0, 255, 0)
165-
166-
# Rotate it off the screen
167-
for i in range(0, 11):
168-
dotstar.shift_right(True)
169-
time.sleep(.1)
170-
171-
time.sleep(1)
172-
# Shift it off the screen
173-
for i in range(0, 11):
174-
dotstar.shift_right()
175-
time.sleep(.1)
176-
177-
"""
178-
for y in range(0, self.rows):
179-
last_pixel = self._dotstar[(y + 1) * self.columns - 1] if rotate else 0
180-
for x in range(self.columns - 1, 0, -1):
181-
self._dotstar[y * self.columns + x] = self._dotstar[y * self.columns + x - 1]
182-
self._dotstar[y * self.columns] = last_pixel
183-
self._update()
184-
185-
def shift_left(self, rotate=False):
186-
"""
187-
Shift all pixels left
188-
189-
:param rotate: (Optional) Rotate the shifted pixels to the right side (default=False)
190-
191-
This example shifts 2 pixels to the left
192-
193-
.. code-block:: python
194-
195-
import time
196-
from adafruit_featherwing import dotstar_featherwing
197-
198-
dotstar = dotstar_featherwing.DotStarFeatherWing()
199-
200-
# Draw Red and Green Pixels
201-
dotstar[5, 3] = (255, 0, 0)
202-
dotstar[6, 3] = (0, 255, 0)
203-
204-
# Rotate it off the screen
205-
for i in range(0, 11):
206-
dotstar.shift_left(True)
207-
time.sleep(.1)
208-
209-
time.sleep(1)
210-
# Shift it off the screen
211-
for i in range(0, 11):
212-
dotstar.shift_left()
213-
time.sleep(.1)
214-
215-
"""
216-
for y in range(0, self.rows):
217-
last_pixel = self._dotstar[y * self.columns] if rotate else 0
218-
for x in range(0, self.columns - 1):
219-
self._dotstar[y * self.columns + x] = self._dotstar[y * self.columns + x + 1]
220-
self._dotstar[(y + 1) * self.columns - 1] = last_pixel
221-
self._update()
222-
223-
def shift_up(self, rotate=False):
224-
"""
225-
Shift all pixels up
226-
227-
:param rotate: (Optional) Rotate the shifted pixels to bottom (default=False)
228-
229-
This example shifts 2 pixels up
230-
231-
.. code-block:: python
232-
233-
import time
234-
from adafruit_featherwing import dotstar_featherwing
235-
236-
dotstar = dotstar_featherwing.DotStarFeatherWing()
237-
238-
# Draw Red and Green Pixels
239-
dotstar[5, 3] = (255, 0, 0)
240-
dotstar[6, 3] = (0, 255, 0)
241-
242-
# Rotate it off the screen
243-
for i in range(0, 5):
244-
dotstar.shift_up(True)
245-
time.sleep(.1)
246-
247-
time.sleep(1)
248-
# Shift it off the screen
249-
for i in range(0, 5):
250-
dotstar.shift_up()
251-
time.sleep(.1)
252-
253-
"""
254-
for x in range(0, self.columns):
255-
last_pixel = self._dotstar[(self.rows - 1) * self.columns + x] if rotate else 0
256-
for y in range(self.rows - 1, 0, -1):
257-
self._dotstar[y * self.columns + x] = self._dotstar[(y - 1) * self.columns + x]
258-
self._dotstar[x] = last_pixel
259-
self._update()
260-
261-
def shift_down(self, rotate=False):
262-
"""
263-
Shift all pixels down
264-
265-
:param rotate: (Optional) Rotate the shifted pixels to top (default=False)
266-
267-
This example shifts 2 pixels down
268-
269-
.. code-block:: python
270-
271-
import time
272-
from adafruit_featherwing import dotstar_featherwing
273-
274-
dotstar = dotstar_featherwing.DotStarFeatherWing()
275-
276-
# Draw Red and Green Pixels
277-
dotstar[5, 3] = (255, 0, 0)
278-
dotstar[6, 3] = (0, 255, 0)
279-
280-
# Rotate it off the screen
281-
for i in range(0, 5):
282-
dotstar.shift_down(True)
283-
time.sleep(.1)
284-
285-
time.sleep(1)
286-
# Shift it off the screen
287-
for i in range(0, 5):
288-
dotstar.shift_down()
289-
time.sleep(.1)
290-
291-
"""
292-
for x in range(0, self.columns):
293-
last_pixel = self._dotstar[x] if rotate else 0
294-
for y in range(0, self.rows - 1):
295-
self._dotstar[y * self.columns + x] = self._dotstar[(y + 1) * self.columns + x]
296-
self._dotstar[(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._dotstar.show()
305-
306-
@property
307-
def auto_write(self):
308-
"""
309-
Whether or not we are automatically updating
310-
If set to false, be sure to call show() to update
311-
312-
This lights DotStars with and without auto_write
313-
314-
.. code-block:: python
315-
316-
import time
317-
from adafruit_featherwing import dotstar_featherwing
318-
319-
dotstar = dotstar_featherwing.DotStarFeatherWing()
320-
dotstar.fill() # Clear any lit Dotstars
321-
dotstar[0, 0] = (255, 255, 255) # Set White
322-
time.sleep(1)
323-
324-
dotstar.auto_write = False
325-
dotstar[1, 0] = (255, 255, 255) # Set White
326-
time.sleep(1)
327-
dotstar.show() # Update the DotStars
328-
329-
"""
330-
return self._auto_write
331-
332-
@auto_write.setter
333-
def auto_write(self, write):
334-
if isinstance(write, bool):
335-
self._auto_write = write
336-
337-
@property
338-
def brightness(self):
339-
"""
340-
Overall brightness of the display
341-
342-
This example changes the brightness
343-
344-
.. code-block:: python
345-
346-
import time
347-
from adafruit_featherwing import dotstar_featherwing
348-
349-
dotstar = dotstar_featherwing.DotStarFeatherWing()
350-
dotstar.brightness = 0
351-
dotstar.fill(0xFFFFFF)
352-
for i in range(0, 6):
353-
dotstar.brightness = (i / 10)
354-
time.sleep(.2)
355-
356-
dotstar.brightness = 0.3
357-
358-
"""
359-
return self._dotstar.brightness
360-
361-
@brightness.setter
362-
def brightness(self, brightness):
363-
self._dotstar.brightness = min(max(brightness, 0.0), 1.0)
364-
self._update()
52+
self._matrix = dotstar.DotStar(clock, data, self.rows * self.columns,
53+
brightness=brightness, auto_write=False)

0 commit comments

Comments
 (0)