|
32 | 32 | import adafruit_dotstar
|
33 | 33 | import time
|
34 | 34 |
|
35 |
| -class DotstarFeatherwing: |
| 35 | +class DotstarFeatherwing(object): |
36 | 36 | """Test, Image, and Animation support for the DotStar featherwing"""
|
37 | 37 |
|
38 | 38 | blank_stripe = [(0, 0, 0),
|
@@ -90,27 +90,25 @@ def set_color(self, row, column, color):
|
90 | 90 | def shift_into_left(self, stripe):
|
91 | 91 | """ Shift a column of pixels into the left side of the display.
|
92 | 92 |
|
93 |
| - :param [(int, int, int)] stripe: A column of pixel colors |
| 93 | + :param [(int, int, int)] stripe: A column of pixel colors. The first at the top. |
94 | 94 | """
|
95 | 95 | for r in range(self.rows):
|
96 | 96 | rightmost = r * self.columns
|
97 | 97 | for c in range(self.columns - 1):
|
98 | 98 | self.display[rightmost + c] = self.display[rightmost + c + 1]
|
99 | 99 | self.display[rightmost + self.columns - 1] = stripe[r]
|
100 |
| - self.display.show() |
101 | 100 |
|
102 | 101 |
|
103 | 102 | def shift_into_right(self, stripe):
|
104 | 103 | """ Shift a column of pixels into the rightside of the display.
|
105 | 104 |
|
106 |
| - :param [(int, int, int)] stripe: A column of pixel colors |
| 105 | + :param [(int, int, int)] stripe: A column of pixel colors. The first at the top. |
107 | 106 | """
|
108 | 107 | for r in range(self.rows):
|
109 | 108 | leftmost = ((r + 1) * self.columns) - 1
|
110 | 109 | for c in range(self.columns - 1):
|
111 | 110 | self.display[leftmost - c] = self.display[(leftmost - c) -1]
|
112 | 111 | self.display[(leftmost - self.columns) + 1] = stripe[r]
|
113 |
| - self.display.show() |
114 | 112 |
|
115 | 113 |
|
116 | 114 | def number_to_pixels(self, x, color):
|
@@ -153,8 +151,10 @@ def shift_in_character(self, font, c, color=(0x00, 0x40, 0x00), delay=0.2):
|
153 | 151 | matrix = self.character_to_numbers(font, 'UNKNOWN')
|
154 | 152 | for stripe in matrix:
|
155 | 153 | self.shift_into_right(self.number_to_pixels(stripe, color))
|
| 154 | + self.show() |
156 | 155 | time.sleep(delay)
|
157 | 156 | self.shift_into_right(self.blank_stripe)
|
| 157 | + self.show() |
158 | 158 | time.sleep(delay)
|
159 | 159 |
|
160 | 160 |
|
@@ -203,13 +203,17 @@ def display_animation(self, animation, colors, count=1, delay=0.1):
|
203 | 203 |
|
204 | 204 | :param [[string]] animation: a list of textual bitmaps, each as described in display_colored_image
|
205 | 205 | :param {char -> (int, int, int)} colors: a map of characters in the image data to colors to use
|
| 206 | + :param int count: the number of times to play the animation |
206 | 207 | :param float delay: the amount of time (seconds) to wait between frames
|
207 | 208 | """
|
208 | 209 | self.clear()
|
| 210 | + first_frame = True |
209 | 211 | while count > 0:
|
210 | 212 | for frame in animation:
|
| 213 | + if not first_frame: |
| 214 | + time.sleep(delay) |
| 215 | + first_frame = False |
211 | 216 | self.display_colored_image(frame, colors)
|
212 |
| - time.sleep(delay) |
213 | 217 | count = count - 1
|
214 | 218 |
|
215 | 219 |
|
|
0 commit comments