diff --git a/adafruit_ht16k33/ht16k33.py b/adafruit_ht16k33/ht16k33.py index 5495ee0..b60317e 100644 --- a/adafruit_ht16k33/ht16k33.py +++ b/adafruit_ht16k33/ht16k33.py @@ -79,7 +79,6 @@ def blink_rate(self, rate=None): self._blink_rate = rate self._write_cmd(_HT16K33_BLINK_CMD | _HT16K33_BLINK_DISPLAYON | rate << 1) - return None @property def brightness(self): @@ -93,7 +92,6 @@ def brightness(self, brightness): brightness = brightness & 0x0F self._brightness = brightness self._write_cmd(_HT16K33_CMD_BRIGHTNESS | brightness) - return None @property def auto_write(self): diff --git a/adafruit_ht16k33/segments.py b/adafruit_ht16k33/segments.py index ab89f57..060f12f 100755 --- a/adafruit_ht16k33/segments.py +++ b/adafruit_ht16k33/segments.py @@ -25,6 +25,7 @@ ================= """ +from time import sleep from adafruit_ht16k33.ht16k33 import HT16K33 __version__ = "0.0.0-auto.0" @@ -235,6 +236,35 @@ def set_digit_raw(self, index, bitmask): if self._auto_write: self.show() + def marquee(self, text, delay=0.25, loop=True): + """ + Automatically scroll the text at the specified delay between characters + + :param str text: The text to display + :param float delay: (optional) The delay in seconds to pause before scrolling + to the next character (default=0.25) + :param bool loop: (optional) Whether to endlessly loop the text (default=True) + + """ + if isinstance(text, str): + self.fill(False) + if loop: + while True: + self._scroll_marquee(text, delay) + else: + self._scroll_marquee(text, delay) + + def _scroll_marquee(self, text, delay): + """Scroll through the text string once using the delay""" + char_is_dot = False + for character in text: + self.print(character) + # Add delay if character is not a dot or more than 2 in a row + if character != '.' or char_is_dot: + sleep(delay) + char_is_dot = (character == '.') + self.show() + class Seg7x4(Seg14x4): """Numeric 7-segment display. It has the same methods as the alphanumeric display, but only supports displaying a limited set of characters.""" diff --git a/examples/ht16k33_segments_simpletest.py b/examples/ht16k33_segments_simpletest.py index 736f1a0..49e0747 100644 --- a/examples/ht16k33_segments_simpletest.py +++ b/examples/ht16k33_segments_simpletest.py @@ -54,3 +54,6 @@ display.set_digit_raw(1, 0b0011111100101101) display.set_digit_raw(2, (0b00111111, 0b00101101)) display.set_digit_raw(3, [0b00111111, 0b00101101]) + +#Show a looping marquee +display.marquee('Deadbeef 192.168.100.102... ', 0.2)