Python Forum
help with scrolling text on RGB Matrix
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with scrolling text on RGB Matrix
#1
I am able to scroll text using Runtext.py but would like to have the text that is displayed, get it from a separate document. This would make it simpler for the end user to change the text being displayed without getting into the actual code.
Would anyone have any solutions for this?
Thanks
Reply
#2
What is runtext.py? A google search came up with multiple example programs with this name. Can you post your code?
Reply
#3
(Apr-09-2024, 05:47 PM)deanhystad Wrote: What is runtext.py? A google search came up with multiple example programs with this name. Can you post your code?

sorry, I'm very new to this. Below is the runtext.py code:

!/usr/bin/env python
# Display a runtext with double-buffering.
from samplebase import SampleBase
from rgbmatrix import graphics
import time


class RunText(SampleBase):
    def __init__(self, *args, **kwargs):
        super(RunText, self).__init__(*args, **kwargs)
        self.parser.add_argument("-t1", "--text", help="The text to scroll on the RGB LED panel", default="Hello world!") 

    def run(self):
        offscreen_canvas = self.matrix.CreateFrameCanvas()
        font = graphics.Font()
        font.LoadFont("../../../fonts/texgyre-27.bdf")
        textColor = graphics.Color(255,0,0)
        pos = offscreen_canvas.width
        my_text = self.args.text

        while True:
            offscreen_canvas.Clear()
            len = graphics.DrawText(offscreen_canvas, font, pos, 25, textColor, my_text)
            pos -= 1
            if (pos + len < 0):
                pos = offscreen_canvas.width

            time.sleep(0.015)
            offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)


# Main function
if __name__ == "__main__":
    run_text = RunText()
    if (not run_text.process()):
        run_text.print_help()
deanhystad write Apr-09-2024, 08:10 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#4
Looks like this one:

https://github.com/hzeller/rpi-rgb-led-m...plebase.py

Your post was missing the last line. I corrected it.

The program already allows setting the message without any programming. Just supply the message in the command line.
Output:
python runtext.py -text "This is the message I want."
Changing the program to read the text from a file looks easy. You can reuse the "text" argument to be the name of a file that contains the text to display. You'll want to give text a default value that is a filename, not the text to display.
self.parser.add_argument("-t1", "--text", help="The text to scroll on the RGB LED panel", default=""message.txt") 
Only a few lines need to change in the run method.
    def run(self):
        offscreen_canvas = self.matrix.CreateFrameCanvas()
        font = graphics.Font()
        font.LoadFont("../../../fonts/texgyre-27.bdf")
        textColor = graphics.Color(255,0,0)
        pos = offscreen_canvas.width
        text_file = self.args.text

        # Read text from file
        with open(text_file, "r") as file:
            my_text = file.read()
 
        while True:
            offscreen_canvas.Clear()
            len = graphics.DrawText(offscreen_canvas, font, pos, 25, textColor, my_text)
            pos -= 1
            if (pos + len < 0):
                pos = offscreen_canvas.width
                # Each time we scrolled the entire message, read the text from the file.
                # To change text, modify the file, and when the current message is done,
                # the new message will be displayed.
                with open(text_file, "r") as file:
                    my_text = file.read()
 
            time.sleep(0.015)
            offscreen_canvas = self.matrix.SwapOnVSync(offscreen_canvas)
I don't have a device for testing this code, so there may be bugs.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Scrolling in Python newpyt 6 856 Nov-23-2023, 09:10 PM
Last Post: newpyt
  Check if two matrix are equal and of not add the matrix to the list quest 3 895 Jul-10-2023, 02:41 AM
Last Post: deanhystad
  raspberry use scrolling text two lines together fishbone 0 1,482 Sep-06-2021, 03:24 AM
Last Post: fishbone
  Can Python be used to create scrolling credits (as follows) digger 3 3,006 Aug-27-2021, 03:15 PM
Last Post: Larz60+
  How to multiply a matrix with herself, until the zero matrix results peanutbutterandjelly 3 3,416 May-03-2021, 06:30 AM
Last Post: Gribouillis
  How to scrolling Picture in x axis kalihotname 1 2,291 Jun-16-2020, 12:18 PM
Last Post: DeaD_EyE
  scrolling a text using loop ebolisa 1 3,362 Apr-27-2019, 02:31 PM
Last Post: ebolisa
  20 x 4 Line 2 scrolling text for LCD-I2C Display RoadieMunky 2 4,866 Mar-04-2018, 10:17 AM
Last Post: RoadieMunky
  matrix from matrix python numpy array shei7141 1 3,749 Jan-16-2017, 06:10 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020