import time import sys import datetime from gpiozero import Buzzer, Button from luma.core.interface.serial import spi, noop from luma.core.render import canvas from luma.led_matrix.device import max7219 from luma.core.legacy import text from luma.core.legacy.font import TINY_FONT, CP437_FONT, LCD_FONT, proportional from PIL import ImageFont import paho.mqtt.client as mqtt import paho.mqtt.subscribe as subscribe def on_message(client, userdata, msg): print(msg.topic + " " + str(msg.payload)) serial = spi(port=0, device=0, gpio=noop()) device = max7219(serial, cascaded=4) button = Button(2) buzzer = Buzzer(17) # mqttc = mqtt.Client(mqtt.CallbackAPIVersion.VERSION2) # mqttc.connect("pinky", 1883, 60) # mqttc.subscribe("homeassistant/input_boolean/aire") # mqttc.on_message = on_message def intro(): _, _, dw, dh = device.bounding_box for h in range(0, dh): with canvas(device) as draw: draw.rectangle((0, 0, dw, h), outline="white", fill="white") time.sleep(0.1) for h in range(0, dh): with canvas(device) as draw: draw.rectangle((0, 0, dw, h), outline="white", fill="black") time.sleep(0.1) time.sleep(0.5) with canvas(device) as draw: draw.rectangle((0, 0, dw, dh), outline="black", fill="black") text(draw, (1, 0), "IAMRELOJ", fill="white", font=proportional(TINY_FONT)) time.sleep(1) def clock(): i=0 while True: i+=1 with canvas(device) as draw: txt = datetime.datetime.now().strftime("%I:%M:%S%p").lstrip("0") if button.is_active: buzzer.on() text(draw, (1, 0), "BUTTON", fill="white", font=proportional(TINY_FONT)) else: buzzer.off() text(draw, (1, 0), txt, fill="white", font=proportional(TINY_FONT)) x = abs(i%64-32) w = (16-(abs(x-16)))/3 draw.rectangle((x,7,x+w,7), outline="white") time.sleep(0.05) intro() time.sleep(1.6) clock()