Scrolling a buffered list of strings across the scroll phat hd

Hey all, ordered the Scroll Bot yesterday and received it today - awesome.

I’m just toying around with the API for the scroll phat hd, but I’m having some trouble building what I’m after.

Ideally, I want to build a function to which I can send individual strings. Each string it receives will be added to the end of a buffer list, and sent out for display on the scroll phat hd in turn, before being popped off the list once that particular string has been shown. If the buffer list is empty, it’ll simply display nothing (or, maybe some type of ambient animation).

I’ve looked at the examples provided and can see the hello world examples scroll a string continually, but this isn’t what I’m after. I have tried my hand at modifying the advanced scrolling example into something similar to what I want, but I’m new to python, so not having much luck decoding what’s going on.

The ultimate goal of this is to display messages sent to it via MQTT, but I’m sure such a function could be used for a whole ton of different applications (tweets, email notifications, etc…)

Can someone point me in the right direction please? Thank you.

So, because I’m not one to give up quite so easily (and because I’ll be shouted at if I don’t at least attempt to solve this problem myself), here’s what I’ve come up with:

#!/usr/bin/env python
import time
import sys

import scrollphathd
from scrollphathd.fonts import font5x7

scrollphathd.rotate(180)

if len(sys.argv) != 2:
    print("\nusage: python echo.py \"message\" \npress CTRL-C to exit\n")
    sys.exit(0)

string = sys.argv[1]
length = len(string)
width = 17
buffer = (length * 6) + width

scrollphathd.write_string(string + "      ", x=width, y=0, font=font5x7, brightness=0.5)

for i in range(buffer):
    scrollphathd.show()
    scrollphathd.scroll(1)
    time.sleep(0.05)

This approach was inspired scroll-text-once.py from the original scroll phat, but isn’t a direct conversion due to the lack of a buffer_len method in the hd. Because of this, I’ve had to improvise, and it seems to work, but can clearly be improved upon.

It’s also not a function, and is lacking the ability to add further strings - but it’s a start. Hopefully, someone here can help me work out the rest :)

I’ll take a look at this tomorrow, as I was trying to do the same and had much less success than you!! One thing it does highlight is that we need to add a buffer_len equivalent to the Scroll pHAT HD library. I’ll get @gadgetoid to add it to his todo list. :-)

1 Like

write_string should return the length of the written text string, anyway, since a buffer_len may be misleading if you- for example- write a text string, selectively clear the area you wrote it to, and then write a shorter text string.

A buffer_shape method may be useful, though.

1 Like

Based on the feedback from @gadgetoid, I’ve modified the script thusly

#snip

string = sys.argv[1] + '      '
buffer = scrollphathd.write_string(string, x=17, y=0, font=font5x7, brightness=0.5)

for i in range(buffer):
    scrollphathd.show()
    scrollphathd.scroll(1)
    time.sleep(0.05)

This feels a little better, but I’m sure can be improved further. For example, I’m having to manually put 6 spaces on the end of the string to avoid the text looping - although I’d imagine this is par for the course.

1 Like

Pretty much, it could be an argument for write_string but it’s overly specific. You could also draw a single clear pixel just past the end of the text to artificially expand out the buffer but just sticking some blank spaces on the end of the text is simpler.