Skip to content

Commit

Permalink
Merge pull request #47 from makermelissa/marquee
Browse files Browse the repository at this point in the history
Ported Marquee function from FeatherWing library
  • Loading branch information
makermelissa authored Jan 15, 2020
2 parents 4e2266c + a1c62d9 commit 5b56a00
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
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)

0 comments on commit 5b56a00

Please sign in to comment.