32
32
import adafruit_dotstar
33
33
import time
34
34
35
+
35
36
class DotstarFeatherwing :
36
37
"""Test, Image, and Animation support for the DotStar featherwing"""
37
38
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 )]
44
40
"""A blank stripe, used internally to separate characters as they are shifted onto the display."""
45
-
41
+
46
42
def __init__ (self , clock , data , brightness = 1.0 ):
47
43
"""Create an interface for the display.
48
44
@@ -52,15 +48,19 @@ def __init__(self, clock, data, brightness=1.0):
52
48
"""
53
49
self .rows = 6
54
50
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
+ )
57
58
58
59
def clear (self ):
59
60
"""Clear the display.
60
61
Does NOT update the LEDs
61
62
"""
62
- self .display .fill ((0 ,0 ,0 ))
63
-
63
+ self .display .fill ((0 , 0 , 0 ))
64
64
65
65
def fill (self , color ):
66
66
"""Fills the wing with a color.
@@ -70,13 +70,11 @@ def fill(self, color):
70
70
"""
71
71
self .display .fill (color )
72
72
73
-
74
73
def show (self ):
75
74
"""Update the LEDs.
76
75
"""
77
76
self .display .show ()
78
77
79
-
80
78
def set_color (self , row , column , color ):
81
79
"""Set the color of the specified pixel.
82
80
@@ -85,17 +83,15 @@ def set_color(self, row, column, color):
85
83
:param (int, int, int) color: The color to set the pixel to
86
84
"""
87
85
self .display [row * self .columns + column ] = color
88
-
89
-
86
+
90
87
def get_color (self , row , column ):
91
88
"""Get the color of the specified pixel. Returns teh color as an RGB tripple.
92
89
93
90
:param int row: The row (0-5) of the pixel to set
94
91
:param int column: The column (0-11) of the pixel to set
95
92
"""
96
93
return self .display [row * self .columns + column ]
97
-
98
-
94
+
99
95
def shift_into_left (self , stripe ):
100
96
""" Shift a column of pixels into the left side of the display.
101
97
@@ -107,7 +103,6 @@ def shift_into_left(self, stripe):
107
103
self .display [rightmost + c ] = self .display [rightmost + c + 1 ]
108
104
self .display [rightmost + self .columns - 1 ] = stripe [r ]
109
105
110
-
111
106
def shift_into_right (self , stripe ):
112
107
""" Shift a column of pixels into the rightside of the display.
113
108
@@ -118,7 +113,6 @@ def shift_into_right(self, stripe):
118
113
for c in range (self .columns - 1 ):
119
114
self .display [leftmost - c ] = self .display [(leftmost - c ) - 1 ]
120
115
self .display [(leftmost - self .columns ) + 1 ] = stripe [r ]
121
-
122
116
123
117
def shift_into_top (self , stripe , offset = 0 ):
124
118
""" Shift a column of pixels into the rightside of the display.
@@ -129,9 +123,10 @@ def shift_into_top(self, stripe, offset=0):
129
123
for c in range (self .columns ):
130
124
bottommost = (self .rows - 1 ) * self .columns
131
125
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
+ ]
133
129
self .display [c ] = stripe [c + offset ]
134
-
135
130
136
131
def number_to_pixels (self , x , color , bit_count = 6 ):
137
132
"""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):
148
143
pixels .append (color )
149
144
val = val >> 1
150
145
return pixels
151
-
152
146
153
147
def character_to_numbers (self , font , char ):
154
148
"""Convert a letter to the sequence of column values to display.
@@ -158,7 +152,6 @@ def character_to_numbers(self, font, char):
158
152
"""
159
153
return font [char ]
160
154
161
-
162
155
def shift_in_character (self , font , c , color = (0x00 , 0x40 , 0x00 ), delay = 0.2 ):
163
156
"""Shifts a single character onto the display from the right edge.
164
157
@@ -170,7 +163,7 @@ def shift_in_character(self, font, c, color=(0x00, 0x40, 0x00), delay=0.2):
170
163
if c .upper () in font :
171
164
matrix = self .character_to_numbers (font , c .upper ())
172
165
else :
173
- matrix = self .character_to_numbers (font , ' UNKNOWN' )
166
+ matrix = self .character_to_numbers (font , " UNKNOWN" )
174
167
for stripe in matrix :
175
168
self .shift_into_right (self .number_to_pixels (stripe , color ))
176
169
self .show ()
@@ -179,7 +172,6 @@ def shift_in_character(self, font, c, color=(0x00, 0x40, 0x00), delay=0.2):
179
172
self .show ()
180
173
time .sleep (delay )
181
174
182
-
183
175
def shift_in_string (self , font , s , color = (0x00 , 0x40 , 0x00 ), delay = 0.2 ):
184
176
"""Shifts a string onto the display from the right edge.
185
177
@@ -191,21 +183,19 @@ def shift_in_string(self, font, s, color=(0x00, 0x40, 0x00), delay=0.2):
191
183
for c in s :
192
184
self .shift_in_character (font , c , color , delay )
193
185
194
-
195
186
# Display an image
196
187
def display_image (self , image , color ):
197
188
"""Display an mono-colored image.
198
189
199
190
:param [string] image: the textual bitmap, 'X' for set pixels, anything else for others
200
191
:param (int) color: the color to set "on" pixels to
201
192
"""
202
- self .display_colored_image (image , {'X' : color })
203
-
193
+ self .display_colored_image (image , {"X" : color })
204
194
205
195
def display_colored_image (self , image , colors ):
206
196
"""Display an multi-colored image.
207
197
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
209
199
corresponding pixel color, anything not in the map is off
210
200
:param {char -> (int, int, int)} colors: a map of characters in the image data to colors to use
211
201
"""
@@ -218,7 +208,6 @@ def display_colored_image(self, image, colors):
218
208
else :
219
209
self .display [index ] = (0 , 0 , 0 )
220
210
self .display .show ()
221
-
222
211
223
212
def display_animation (self , animation , colors , count = 1 , delay = 0.1 ):
224
213
"""Display a multi-colored animation.
@@ -237,8 +226,3 @@ def display_animation(self, animation, colors, count=1, delay=0.1):
237
226
first_frame = False
238
227
self .display_colored_image (frame , colors )
239
228
count = count - 1
240
-
241
-
242
-
243
-
244
-
0 commit comments