added blink testing script
This commit is contained in:
parent
81339b159f
commit
912ffd8e5d
9 changed files with 196 additions and 43 deletions
|
|
@ -11,88 +11,76 @@ options.cols = 64
|
|||
options.chain_length = 2
|
||||
options.parallel = 1
|
||||
options.hardware_mapping = 'regular' # If you have an Adafruit HAT: 'adafruit-hat'
|
||||
matrix = RGBMatrix(options = options)
|
||||
matrix = RGBMatrix(options=options)
|
||||
|
||||
|
||||
# Load image and make sure it fits our screen.
|
||||
def pure_pil_alpha_to_color_v2(image, color=(0, 0, 0)):
|
||||
"""Alpha composite an RGBA Image with a specified color.
|
||||
|
||||
Simpler, faster version than the solutions above.
|
||||
|
||||
Source: http://stackoverflow.com/a/9459208/284318
|
||||
|
||||
Keyword Arguments:
|
||||
image -- PIL RGBA Image object
|
||||
color -- Tuple r, g, b (default 255, 255, 255)
|
||||
|
||||
"""
|
||||
image.load() # needed for split()
|
||||
background = Image.new('RGB', image.size, color)
|
||||
background.paste(image, mask=image.split()[3]) # 3 is the alpha channel
|
||||
return background
|
||||
|
||||
image = Image.open("../prootface.bmp")
|
||||
image.thumbnail((128,62), Image.ANTIALIAS)
|
||||
image.thumbnail((128, 62), Image.ANTIALIAS)
|
||||
RGBImage = pure_pil_alpha_to_color_v2(image)
|
||||
|
||||
|
||||
|
||||
|
||||
# offscreen canvas that can be written to which can then be set to the matrix async
|
||||
# offscreen canvas that can be written to and then set to the matrix asynchronously
|
||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||
offscreen_canvas.brightness = 50
|
||||
offscreen__text_canvas = matrix.CreateFrameCanvas()
|
||||
offscreen__text_canvas.brightness = 50
|
||||
offscreen__text_canvas.SetImage(RGBImage)
|
||||
offscreen_text_canvas = matrix.CreateFrameCanvas()
|
||||
offscreen_text_canvas.brightness = 50
|
||||
offscreen_text_canvas.SetImage(RGBImage)
|
||||
|
||||
|
||||
def updateScreen():
|
||||
def update_screen():
|
||||
global color, matrix, offscreen_canvas
|
||||
nextCanvas = offscreen_canvas
|
||||
if(color == 1):
|
||||
offscreen_canvas.Fill(255,255,255)
|
||||
nextCanvas = offscreen_canvas
|
||||
elif(color == 0):
|
||||
offscreen_canvas.Fill(255,0,0)
|
||||
nextCanvas = offscreen_canvas
|
||||
elif(color == 2):
|
||||
nextCanvas = offscreen__text_canvas
|
||||
|
||||
nextCanvas = matrix.SwapOnVSync(nextCanvas)
|
||||
|
||||
next_canvas = offscreen_canvas
|
||||
if color == 1:
|
||||
next_canvas.Fill(255, 255, 255)
|
||||
elif color == 0:
|
||||
next_canvas.Fill(255, 0, 0)
|
||||
elif color == 2:
|
||||
next_canvas = offscreen_text_canvas
|
||||
|
||||
next_canvas = matrix.SwapOnVSync(next_canvas)
|
||||
|
||||
|
||||
color = 0
|
||||
def toggleColor():
|
||||
def toggle_color():
|
||||
global color
|
||||
color += 1
|
||||
color %= 3
|
||||
|
||||
updateScreen()
|
||||
|
||||
update_screen()
|
||||
|
||||
|
||||
# functions called by the MQTT listener
|
||||
def on_connect(client, userdata, flags, responseCode):
|
||||
print("Connected to MQTT broker with result code " + str(responseCode))
|
||||
def on_connect(client, userdata, flags, response_code):
|
||||
print("Connected to MQTT broker with result code " + str(response_code))
|
||||
client.subscribe("test")
|
||||
|
||||
|
||||
def on_message(client, userdata, message):
|
||||
print("Received message '" + str(message.payload) + "' on topic '"
|
||||
+ message.topic + "' with QoS " + str(message.qos))
|
||||
toggleColor()
|
||||
|
||||
+ message.topic + "' with QoS " + str(message.qos))
|
||||
toggle_color()
|
||||
|
||||
# MQTT broker configuration
|
||||
broker_address = "10.1.13.173" # Replace with your MQTT broker's address
|
||||
broker_port = 1883
|
||||
broker_keepalive = 60
|
||||
|
||||
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
|
||||
client.connect(broker_address, broker_port, broker_keepalive)
|
||||
|
||||
client.loop_start()
|
||||
|
||||
|
||||
while True:
|
||||
time.sleep(0.005)
|
||||
|
||||
time.sleep(0.005)
|
||||
Loading…
Add table
Add a link
Reference in a new issue