Skip to content

Commit 97937ad

Browse files
authored
Merge pull request #52 from makermelissa/matrix_scroll
Added print_hex function for segmented displays
2 parents ab9ff67 + d1bbc7f commit 97937ad

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

adafruit_ht16k33/matrix.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ def shift(self, x, y, rotate=False):
5959
6060
:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
6161
"""
62+
auto_write = self.auto_write
63+
self._auto_write = False
6264
if x > 0: # Shift Right
6365
for _ in range(x):
6466
for row in range(0, self.rows):
@@ -87,7 +89,8 @@ def shift(self, x, y, rotate=False):
8789
for row in range(0, self.rows - 1):
8890
self[col, row] = self[col, row + 1]
8991
self[col, self.rows - 1] = last_pixel
90-
if self._auto_write:
92+
self._auto_write = auto_write
93+
if auto_write:
9194
self.show()
9295
#pylint: enable=too-many-branches
9396

adafruit_ht16k33/segments.py

+10
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,16 @@ def print(self, value):
162162
if self._auto_write:
163163
self.show()
164164

165+
def print_hex(self, value):
166+
"""Print the value as a hexidecimal string to the display."""
167+
if isinstance(value, int):
168+
if 0 <= value <= 0xFFFF:
169+
self.print('{0:X}'.format(value))
170+
else:
171+
raise ValueError('Value out of displayable range: {}'.format(value))
172+
else:
173+
self.print(value)
174+
165175
def __setitem__(self, key, value):
166176
self._put(value, key)
167177
if self._auto_write:

examples/ht16k33_segments_simpletest.py

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
display.print(42)
3131
time.sleep(2)
3232

33+
# Or, can print a hexadecimal value
34+
display.print_hex(0xFF23)
35+
time.sleep(2)
36+
3337
# Or, can set indivdual digits / characters
3438
# Set the first character to '1':
3539
display[0] = '1'

0 commit comments

Comments
 (0)