testing setting image
This commit is contained in:
parent
9e573f4f33
commit
f7fada966d
2 changed files with 31 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
from rgbmatrix import RGBMatrix, RGBMatrixOptions
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import time
|
import time
|
||||||
|
from PIL import Image
|
||||||
|
|
||||||
|
|
||||||
# Configuration for the matrix
|
# Configuration for the matrix
|
||||||
|
|
@ -16,19 +17,41 @@ matrix = RGBMatrix(options = options)
|
||||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||||
|
|
||||||
|
|
||||||
|
image = Image.open("../testImg.bmp")
|
||||||
|
|
||||||
|
# Make image fit our screen.
|
||||||
|
image.thumbnail((matrix.width, matrix.height), Image.ANTIALIAS)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def updateScreen():
|
||||||
|
global color
|
||||||
|
if(color == 1):
|
||||||
|
offscreen_canvas.Fill(255,255,255)
|
||||||
|
elif(color == 0):
|
||||||
|
offscreen_canvas.Fill(255,0,0)
|
||||||
|
elif(color == 2):
|
||||||
|
matrix.SetImage(image.convert('RGB'))
|
||||||
|
|
||||||
|
offscreen_canvas.brightness = 50
|
||||||
|
offscreen_canvas = matrix.SwapOnVSync(offscreen_canvas)
|
||||||
|
|
||||||
|
|
||||||
color = 0
|
color = 0
|
||||||
def toggleColor():
|
def toggleColor():
|
||||||
global color
|
global color
|
||||||
if(color == 1):
|
color += 1
|
||||||
color = 0
|
color %= 3
|
||||||
else:
|
|
||||||
color = 1
|
updateScreen()
|
||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
# functions called by the MQTT listener
|
||||||
print("Connected to MQTT broker with result code " + str(rc))
|
def on_connect(client, userdata, flags, responseCode):
|
||||||
|
print("Connected to MQTT broker with result code " + str(responseCode))
|
||||||
client.subscribe("test")
|
client.subscribe("test")
|
||||||
|
|
||||||
|
|
||||||
def on_message(client, userdata, message):
|
def on_message(client, userdata, message):
|
||||||
print("Received message '" + str(message.payload) + "' on topic '"
|
print("Received message '" + str(message.payload) + "' on topic '"
|
||||||
+ message.topic + "' with QoS " + str(message.qos))
|
+ message.topic + "' with QoS " + str(message.qos))
|
||||||
|
|
@ -44,13 +67,7 @@ client.connect("10.1.13.173", 1883, 60) # Replace with your MQTT broker's addre
|
||||||
|
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
time.sleep(0.005)
|
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)
|
|
||||||
|
|
|
||||||
0
rpi/show-image.py
Normal file
0
rpi/show-image.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue