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.