diff --git a/adafruit_ht16k33/matrix.py b/adafruit_ht16k33/matrix.py index c8f4832..b57d6e2 100755 --- a/adafruit_ht16k33/matrix.py +++ b/adafruit_ht16k33/matrix.py @@ -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): @@ -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 diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index 060f12f..1b2bb91 100755 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -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: diff --git a/examples/ht16k33_segments_simpletest.py b/examples/ht16k33_segments_simpletest.py index 49e0747..a12d703 100644 --- a/examples/ht16k33_segments_simpletest.py +++ b/examples/ht16k33_segments_simpletest.py @@ -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'