3232import adafruit_dotstar
3333import time
3434
35+
3536class DotstarFeatherwing :
3637 """Test, Image, and Animation support for the DotStar featherwing"""
3738
38- blank_stripe = [(0 , 0 , 0 ),
39- (0 , 0 , 0 ),
40- (0 , 0 , 0 ),
41- (0 , 0 , 0 ),
42- (0 , 0 , 0 ),
43- (0 , 0 , 0 )]
39+ blank_stripe = [(0 , 0 , 0 ), (0 , 0 , 0 ), (0 , 0 , 0 ), (0 , 0 , 0 ), (0 , 0 , 0 ), (0 , 0 , 0 )]
4440 """A blank stripe, used internally to separate characters as they are shifted onto the display."""
45-
41+
4642 def __init__ (self , clock , data , brightness = 1.0 ):
4743 """Create an interface for the display.
4844
@@ -52,15 +48,19 @@ def __init__(self, clock, data, brightness=1.0):
5248 """
5349 self .rows = 6
5450 self .columns = 12
55- self .display = adafruit_dotstar .DotStar (clock , data , self .rows * self .columns , brightness , False )
56-
51+ self .display = adafruit_dotstar .DotStar (
52+ clock ,
53+ data ,
54+ self .rows * self .columns ,
55+ brightness = brightness ,
56+ auto_write = False ,
57+ )
5758
5859 def clear (self ):
5960 """Clear the display.
6061 Does NOT update the LEDs
6162 """
62- self .display .fill ((0 ,0 ,0 ))
63-
63+ self .display .fill ((0 , 0 , 0 ))
6464
6565 def fill (self , color ):
6666 """Fills the wing with a color.
@@ -70,13 +70,11 @@ def fill(self, color):
7070 """
7171 self .display .fill (color )
7272
73-
7473 def show (self ):
7574 """Update the LEDs.
7675 """
7776 self .display .show ()
7877
79-
8078 def set_color (self , row , column , color ):
8179 """Set the color of the specified pixel.
8280
@@ -85,17 +83,15 @@ def set_color(self, row, column, color):
8583 :param (int, int, int) color: The color to set the pixel to
8684 """
8785 self .display [row * self .columns + column ] = color
88-
89-
86+
9087 def get_color (self , row , column ):
9188 """Get the color of the specified pixel. Returns teh color as an RGB tripple.
9289
9390 :param int row: The row (0-5) of the pixel to set
9491 :param int column: The column (0-11) of the pixel to set
9592 """
9693 return self .display [row * self .columns + column ]
97-
98-
94+
9995 def shift_into_left (self , stripe ):
10096 """ Shift a column of pixels into the left side of the display.
10197
@@ -107,7 +103,6 @@ def shift_into_left(self, stripe):
107103 self .display [rightmost + c ] = self .display [rightmost + c + 1 ]
108104 self .display [rightmost + self .columns - 1 ] = stripe [r ]
109105
110-
111106 def shift_into_right (self , stripe ):
112107 """ Shift a column of pixels into the rightside of the display.
113108
@@ -118,7 +113,6 @@ def shift_into_right(self, stripe):
118113 for c in range (self .columns - 1 ):
119114 self .display [leftmost - c ] = self .display [(leftmost - c ) - 1 ]
120115 self .display [(leftmost - self .columns ) + 1 ] = stripe [r ]
121-
122116
123117 def shift_into_top (self , stripe , offset = 0 ):
124118 """ Shift a column of pixels into the rightside of the display.
@@ -129,9 +123,10 @@ def shift_into_top(self, stripe, offset=0):
129123 for c in range (self .columns ):
130124 bottommost = (self .rows - 1 ) * self .columns
131125 for r in range (self .rows - 1 ):
132- self .display [bottommost + c - (r * self .columns )] = self .display [bottommost + c - ((r + 1 ) * self .columns )]
126+ self .display [bottommost + c - (r * self .columns )] = self .display [
127+ bottommost + c - ((r + 1 ) * self .columns )
128+ ]
133129 self .display [c ] = stripe [c + offset ]
134-
135130
136131 def number_to_pixels (self , x , color , bit_count = 6 ):
137132 """Convert an integer (0..63) into an array of 6 pixels.
@@ -148,7 +143,6 @@ def number_to_pixels(self, x, color, bit_count=6):
148143 pixels .append (color )
149144 val = val >> 1
150145 return pixels
151-
152146
153147 def character_to_numbers (self , font , char ):
154148 """Convert a letter to the sequence of column values to display.
@@ -158,7 +152,6 @@ def character_to_numbers(self, font, char):
158152 """
159153 return font [char ]
160154
161-
162155 def shift_in_character (self , font , c , color = (0x00 , 0x40 , 0x00 ), delay = 0.2 ):
163156 """Shifts a single character onto the display from the right edge.
164157
@@ -170,7 +163,7 @@ def shift_in_character(self, font, c, color=(0x00, 0x40, 0x00), delay=0.2):
170163 if c .upper () in font :
171164 matrix = self .character_to_numbers (font , c .upper ())
172165 else :
173- matrix = self .character_to_numbers (font , ' UNKNOWN' )
166+ matrix = self .character_to_numbers (font , " UNKNOWN" )
174167 for stripe in matrix :
175168 self .shift_into_right (self .number_to_pixels (stripe , color ))
176169 self .show ()
@@ -179,7 +172,6 @@ def shift_in_character(self, font, c, color=(0x00, 0x40, 0x00), delay=0.2):
179172 self .show ()
180173 time .sleep (delay )
181174
182-
183175 def shift_in_string (self , font , s , color = (0x00 , 0x40 , 0x00 ), delay = 0.2 ):
184176 """Shifts a string onto the display from the right edge.
185177
@@ -191,21 +183,19 @@ def shift_in_string(self, font, s, color=(0x00, 0x40, 0x00), delay=0.2):
191183 for c in s :
192184 self .shift_in_character (font , c , color , delay )
193185
194-
195186 # Display an image
196187 def display_image (self , image , color ):
197188 """Display an mono-colored image.
198189
199190 :param [string] image: the textual bitmap, 'X' for set pixels, anything else for others
200191 :param (int) color: the color to set "on" pixels to
201192 """
202- self .display_colored_image (image , {'X' : color })
203-
193+ self .display_colored_image (image , {"X" : color })
204194
205195 def display_colored_image (self , image , colors ):
206196 """Display an multi-colored image.
207197
208- :param [string] image: the textual bitmap, character are looked up in colors for the
198+ :param [string] image: the textual bitmap, character are looked up in colors for the
209199 corresponding pixel color, anything not in the map is off
210200 :param {char -> (int, int, int)} colors: a map of characters in the image data to colors to use
211201 """
@@ -218,7 +208,6 @@ def display_colored_image(self, image, colors):
218208 else :
219209 self .display [index ] = (0 , 0 , 0 )
220210 self .display .show ()
221-
222211
223212 def display_animation (self , animation , colors , count = 1 , delay = 0.1 ):
224213 """Display a multi-colored animation.
@@ -237,8 +226,3 @@ def display_animation(self, animation, colors, count=1, delay=0.1):
237226 first_frame = False
238227 self .display_colored_image (frame , colors )
239228 count = count - 1
240-
241-
242-
243-
244-
0 commit comments