|
32 | 32 | import adafruit_dotstar |
33 | 33 | import time |
34 | 34 |
|
35 | | -class DotstarFeatherwing(object): |
| 35 | +class DotstarFeatherwing: |
36 | 36 | """Test, Image, and Animation support for the DotStar featherwing""" |
37 | 37 |
|
38 | 38 | blank_stripe = [(0, 0, 0), |
@@ -99,27 +99,40 @@ def shift_into_left(self, stripe): |
99 | 99 | self.display[rightmost + self.columns - 1] = stripe[r] |
100 | 100 |
|
101 | 101 |
|
102 | | - def shift_into_right(self, stripe): |
| 102 | + def shift_into_right(self, stripe): |
103 | 103 | """ Shift a column of pixels into the rightside of the display. |
104 | 104 |
|
105 | 105 | :param [(int, int, int)] stripe: A column of pixel colors. The first at the top. |
106 | 106 | """ |
107 | 107 | for r in range(self.rows): |
108 | 108 | leftmost = ((r + 1) * self.columns) - 1 |
109 | 109 | for c in range(self.columns - 1): |
110 | | - self.display[leftmost - c] = self.display[(leftmost - c) -1] |
| 110 | + self.display[leftmost - c] = self.display[(leftmost - c) - 1] |
111 | 111 | self.display[(leftmost - self.columns) + 1] = stripe[r] |
112 | 112 |
|
113 | 113 |
|
114 | | - def number_to_pixels(self, x, color): |
| 114 | + def shift_into_top(self, stripe, offset=0): |
| 115 | + """ Shift a column of pixels into the rightside of the display. |
| 116 | +
|
| 117 | + :param [(int, int, int)] stripe: A column of pixel colors. The first at the top. |
| 118 | + :param int offset: The offset into stripe of the first pixel value to take. |
| 119 | + """ |
| 120 | + for c in range(self.columns): |
| 121 | + bottommost = (self.rows - 1) * self.columns |
| 122 | + for r in range(self.rows - 1): |
| 123 | + self.display[bottommost + c - (r * self.columns)] = self.display[bottommost + c - ((r + 1) * self.columns)] |
| 124 | + self.display[c] = stripe[c + offset] |
| 125 | + |
| 126 | + |
| 127 | + def number_to_pixels(self, x, color, bit_count=6): |
115 | 128 | """Convert an integer (0..63) into an array of 6 pixels. |
116 | 129 |
|
117 | 130 | :param int x: integer to convert into binary pixel values; LSB is topmost. |
118 | 131 | :param (int, int, int) color: the color to set "on" pixels to |
119 | 132 | """ |
120 | 133 | val = x |
121 | 134 | pixels = [] |
122 | | - for b in range(self.rows): |
| 135 | + for b in range(bit_count): |
123 | 136 | if val & 1 == 0: |
124 | 137 | pixels.append((0, 0, 0)) |
125 | 138 | else: |
|
0 commit comments