2023-05-18 09:51:21 +02:00
|
|
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
|
|
|
import paho.mqtt.client as mqtt
|
2023-05-18 10:13:13 +02:00
|
|
|
import time
|
2023-05-18 09:51:21 +02:00
|
|
|
|
|
|
|
|
2023-05-18 10:13:13 +02:00
|
|
|
# Configuration for the matrix
|
|
|
|
options = RGBMatrixOptions()
|
|
|
|
options.rows = 32
|
2023-05-18 10:28:54 +02:00
|
|
|
options.cols = 64
|
|
|
|
options.chain_length = 2
|
2023-05-18 10:13:13 +02:00
|
|
|
options.parallel = 1
|
|
|
|
options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
|
|
|
|
matrix = RGBMatrix(options = options)
|
2023-05-18 09:51:21 +02:00
|
|
|
|
2023-05-18 10:13:13 +02:00
|
|
|
# offscreen canvas that can be written to which can then be set to the matrix async
|
|
|
|
offscreen_canvas = matrix.CreateFrameCanvas()
|
2023-05-18 09:51:21 +02:00
|
|
|
|
|
|
|
|
2023-05-18 10:13:13 +02:00
|
|
|
color = 0
|
2023-05-18 10:15:06 +02:00
|
|
|
def toggleColor():
|
2023-05-18 10:13:13 +02:00
|
|
|
global color
|
|
|
|
if(color == 1):
|
|
|
|
color = 0
|
|
|
|
else:
|
|
|
|
color = 1
|
|
|
|
|
2023-05-18 09:51:21 +02:00
|
|
|
|
|
|
|
def on_connect(client, userdata, flags, rc):
|
|
|
|
print("Connected to MQTT broker with result code " + str(rc))
|
|
|
|
client.subscribe("test")
|
|
|
|
|
2023-05-18 10:13:13 +02:00
|
|
|
def on_message(client, userdata, message):
|
|
|
|
print("Received message '" + str(message.payload) + "' on topic '"
|
|
|
|
+ message.topic + "' with QoS " + str(message.qos))
|
|
|
|
toggleColor()
|
|
|
|
|
2023-05-18 09:51:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
client = mqtt.Client()
|
|
|
|
client.on_connect = on_connect
|
|
|
|
client.on_message = on_message
|
|
|
|
|
|
|
|
client.connect("10.1.13.173", 1883, 60) # Replace with your MQTT broker's address
|
|
|
|
|
2023-05-18 10:13:13 +02:00
|
|
|
client.loop_start()
|
|
|
|
|
|
|
|
while True:
|
|
|
|
time.sleep(0.005)
|
|
|
|
|
|
|
|
if(color == 1):
|
|
|
|
offscreen_canvas.Fill(255,255,255)
|
|
|
|
else:
|
|
|
|
offscreen_canvas.Fill(255,0,0)
|
|
|
|
|
|
|
|
offscreen_canvas.brightness = 50
|
|
|
|
offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas)
|