How to make a Unicornhat HD Scrolling Text Loop?


#1

Hello!

I am looking for a way to make this python script repeat itself. It is the scrolling text example for the Unicornhat HD and it works great allowing you to edit the text, but once it hits the end of the text it will end the script. Would anyone know how to edit the script to make the text loop?

here is the link to the .py file


#2

You could just repeat the drawing loop, turning:

for scroll in range(text_width - width):
    for x in range(width):
        for y in range(height):
            pixel = image.getpixel((x+scroll, y))
            r, g, b = [int(n) for n in pixel]
            unicornhathd.set_pixel(width-1-x, y, r, g, b)

    unicornhathd.show()
    time.sleep(0.01)

into:

while True:
    for scroll in range(text_width - width):
        for x in range(width):
            for y in range(height):
                pixel = image.getpixel((x+scroll, y))
                r, g, b = [int(n) for n in pixel]
                unicornhathd.set_pixel(width-1-x, y, r, g, b)

        unicornhathd.show()
        time.sleep(0.01)

#3

that is really simple, i will give that a shot!


#4

so i tried this last night, and i must have messed something up with it, because adding the "while True: to the script causes it to not lunch. any ideas what could have gone wrong?


#5

Do you see any errors, or does the Unicorn HAT just not update?

If it’s the latter, it’s possible the show() method isn’t being called in the loop.


#6

nothing happens with the UnicornHat HD when i execute it. it seems like it is not being called.


#7

Could you post your code here?

Use three backticks to preserve formatting:

```
Like so
```