Skip to content

Added print_hex function for segmented displays #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion adafruit_ht16k33/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def shift(self, x, y, rotate=False):

:param rotate: (Optional) Rotate the shifted pixels to the left side (default=False)
"""
auto_write = self.auto_write
self._auto_write = False
if x > 0: # Shift Right
for _ in range(x):
for row in range(0, self.rows):
Expand Down Expand Up @@ -87,7 +89,8 @@ def shift(self, x, y, rotate=False):
for row in range(0, self.rows - 1):
self[col, row] = self[col, row + 1]
self[col, self.rows - 1] = last_pixel
if self._auto_write:
self._auto_write = auto_write
if auto_write:
self.show()
#pylint: enable=too-many-branches

Expand Down
10 changes: 10 additions & 0 deletions adafruit_ht16k33/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ def print(self, value):
if self._auto_write:
self.show()

def print_hex(self, value):
"""Print the value as a hexidecimal string to the display."""
if isinstance(value, int):
if 0 <= value <= 0xFFFF:
self.print('{0:X}'.format(value))
else:
raise ValueError('Value out of displayable range: {}'.format(value))
else:
self.print(value)

def __setitem__(self, key, value):
self._put(value, key)
if self._auto_write:
Expand Down
4 changes: 4 additions & 0 deletions examples/ht16k33_segments_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
display.print(42)
time.sleep(2)

# Or, can print a hexadecimal value
display.print_hex(0xFF23)
time.sleep(2)

# Or, can set indivdual digits / characters
# Set the first character to '1':
display[0] = '1'
Expand Down