Skip to content

Commit a1c62d9

Browse files
committed
Ported Marquee function from FeatherWing library
1 parent f836604 commit a1c62d9

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

adafruit_ht16k33/ht16k33.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ def blink_rate(self, rate=None):
7979
self._blink_rate = rate
8080
self._write_cmd(_HT16K33_BLINK_CMD |
8181
_HT16K33_BLINK_DISPLAYON | rate << 1)
82-
return None
8382

8483
@property
8584
def brightness(self):
@@ -93,7 +92,6 @@ def brightness(self, brightness):
9392
brightness = brightness & 0x0F
9493
self._brightness = brightness
9594
self._write_cmd(_HT16K33_CMD_BRIGHTNESS | brightness)
96-
return None
9795

9896
@property
9997
def auto_write(self):

adafruit_ht16k33/segments.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
=================
2626
"""
2727

28+
from time import sleep
2829
from adafruit_ht16k33.ht16k33 import HT16K33
2930

3031
__version__ = "0.0.0-auto.0"
@@ -235,6 +236,35 @@ def set_digit_raw(self, index, bitmask):
235236
if self._auto_write:
236237
self.show()
237238

239+
def marquee(self, text, delay=0.25, loop=True):
240+
"""
241+
Automatically scroll the text at the specified delay between characters
242+
243+
:param str text: The text to display
244+
:param float delay: (optional) The delay in seconds to pause before scrolling
245+
to the next character (default=0.25)
246+
:param bool loop: (optional) Whether to endlessly loop the text (default=True)
247+
248+
"""
249+
if isinstance(text, str):
250+
self.fill(False)
251+
if loop:
252+
while True:
253+
self._scroll_marquee(text, delay)
254+
else:
255+
self._scroll_marquee(text, delay)
256+
257+
def _scroll_marquee(self, text, delay):
258+
"""Scroll through the text string once using the delay"""
259+
char_is_dot = False
260+
for character in text:
261+
self.print(character)
262+
# Add delay if character is not a dot or more than 2 in a row
263+
if character != '.' or char_is_dot:
264+
sleep(delay)
265+
char_is_dot = (character == '.')
266+
self.show()
267+
238268
class Seg7x4(Seg14x4):
239269
"""Numeric 7-segment display. It has the same methods as the alphanumeric display, but only
240270
supports displaying a limited set of characters."""

examples/ht16k33_segments_simpletest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,6 @@
5454
display.set_digit_raw(1, 0b0011111100101101)
5555
display.set_digit_raw(2, (0b00111111, 0b00101101))
5656
display.set_digit_raw(3, [0b00111111, 0b00101101])
57+
58+
#Show a looping marquee
59+
display.marquee('Deadbeef 192.168.100.102... ', 0.2)

0 commit comments

Comments
 (0)