Open galaxyZ2 opened 1 year ago
Apologies, I dont know how to comment the code in a readable format:
''' from flask import Flask, request, render_template, redirect from rgbmatrix import RGBMatrix, RGBMatrixOptions, graphics from flask_wtf import FlaskForm from wtforms import StringField, SubmitField, SelectField import logging, os from pprint import pprint
app = Flask(name) app.config['SECRET_KEY'] = 'secretkey'
options = RGBMatrixOptions() options.rows = 32 options.cols = 32 options.chain_length = 1 options.brightness = 100 options.pwm_bits = 1 options.pwm_lsb_nanoseconds = 100 options.gpio_slowdown = 5 options.hardware_mapping = 'adafruit-hat' matrix = RGBMatrix(options = options)
canvas = matrix.CreateFrameCanvas() x = int y = int message = str color = str
font = graphics.Font()
class DisplayForm(FlaskForm): message = StringField('Messages') color = StringField('Color') submit = SubmitField('Submit')
@app.route('/display', methods=['GET','POST']) def display(): global color, x, y
form = DisplayForm()
global message
if form.validate_on_submit():
if not form.message.data or not form.color.data:
return render_template('display.html', form=form, error_mesage='Please enter the values')
x = 0
y = 20
message = form.message.data
color_code = form.color.data
r, g, b = map(int, color_code.split(","))
color = graphics.Color(r,g,b)
font.LoadFont('/home/linux/rpi-rgb-led-matrix/fonts/7x13.bdf')
canvas.Clear()
graphics.DrawText(canvas, font, x, y, color, message)
matrix.SwapOnVSync(canvas)
#return 'Displaying message: {}'.format(message)
return render_template('display.html', form=form, color=color, x=x, y=y)
@app.route('/stop', methods=['GET', 'POST']) def stop(): form = DisplayForm()
canvas.Clear()
#Push the cleared canvas to the matrix
matrix.SwapOnVSync(canvas)
return render_template('display.html', form=form, x=x, y=y)
@app.route('/move_left', methods=['GET', 'POST']) def move_left(): global x, message x = x - 1 canvas.Clear() graphics.DrawText(canvas, font, x, y, color, message) matrix.SwapOnVSync(canvas) return redirect('/')
@app.route('/move_right', methods=['GET', 'POST']) def move_right(): global x x = x + 1 canvas.Clear() graphics.DrawText(canvas, font, x, y, color, message) matrix.SwapOnVSync(canvas) return redirect('/')
@app.route('/move_up', methods=['GET', 'POST']) def move_up(): global y y -= 1 canvas.Clear() graphics.DrawText(canvas, font, x, y, color, message) matrix.SwapOnVSync(canvas) return redirect('/')
@app.route('/move_down', methods=['GET', 'POST']) def move_down(): global y, message y += 1 canvas.Clear() graphics.DrawText(canvas, font, x, y, color, message) matrix.SwapOnVSync(canvas) return redirect('/')
if name == 'main': app.run(host='192.168.1.112', port=1234) '''
Usually you'd do triple ticks to have code shown properly formatted.
It looks like you're not assigning the return value of SwapToVSync()
to canvas. Without that, you don't have double-buffering.
canvas = matrix.SwapOnVSync(canvas)
(can you repost formated code / edit post? there is 'add code' icon above post form)
My guess is that message
variable in display()
is local, other functions refer message
from global scope
(can you repost formated code / edit post? there is 'add code' icon above post form)
My guess is that
message
variable indisplay()
is local, other functions refermessage
from global scope
BINGO!! Thank you! What a small mistake, but it works beautifully if i change it! Thank you!
Usually you'd do triple ticks to have code shown properly formatted.
It looks like you're not assigning the return value of
SwapToVSync()
to canvas. Without that, you don't have double-buffering.canvas = matrix.SwapOnVSync(canvas)
Thank you! It ended up being the second comment! All good thank you for the ideas!
You still need canvas = matrix.SwapOnVSync(canvas)
for a flickering-free image transition.
You still need
canvas = matrix.SwapOnVSync(canvas)
for a flickering-free image transition.
Forgot to mention that I did add the line as suggested! Much appreciated!
Hello Everyone,
I am totally new to programming, and I choose a hobby project in the form of a raspberry pi 4 with an adafruit-hat controlling a 32x32 matrix.
I wrote a python script, which is working quite beautifully, however when I use the text mover functions (either of them) the text I initially set will change to "utf-8" and keep moving according to the function.
What could cause this?
Any help is much appreciated!