Skip to content

Ported Marquee function from FeatherWing library #47

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 1 commit into from
Jan 15, 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
2 changes: 0 additions & 2 deletions adafruit_ht16k33/ht16k33.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand Down
30 changes: 30 additions & 0 deletions adafruit_ht16k33/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
=================
"""

from time import sleep
from adafruit_ht16k33.ht16k33 import HT16K33

__version__ = "0.0.0-auto.0"
Expand Down Expand Up @@ -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."""
Expand Down
3 changes: 3 additions & 0 deletions examples/ht16k33_segments_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)