Displaying Telegram text on MAX7219 dot matrix using Raspberry Pi.
from gpiozero import Buzzer | |
from time import time, sleep, strftime | |
from datetime import datetime | |
import telepot | |
from luma.core.interface.serial import spi, noop | |
from luma.core.render import canvas | |
from luma.core.virtual import viewport | |
from luma.led_matrix.device import max7219 | |
from luma.core.legacy import text, show_message | |
from luma.core.legacy.font import proportional, CP437_FONT, LCD_FONT | |
serial = spi(port=0, device=0, gpio=noop()) | |
device = max7219(serial, width=32, height=8, block_orientation=-90) | |
device.contrast(5) | |
virtual = viewport(device, width=32, height=16) | |
buzzer = Buzzer(26) | |
def handle(msg): | |
global telegramText | |
global chat_id | |
global showMessage | |
chat_id = msg['chat']['id'] | |
telegramText = msg['text'] | |
print('Message received from ' + str(chat_id)) | |
if telegramText == '/start': | |
bot.sendMessage(chat_id, 'Welcome to Idris Dot Matrix Bot') | |
else: | |
buzzer.beep(0.1, 0.1, 2) | |
showMessage = True | |
bot.sendMessage(chat_id, 'Text received.') | |
bot = telepot.Bot('PUT YOUR TELEGRAM BOT TOKEN HERE') | |
bot.message_loop(handle) | |
show_message(device, 'Telegram Bot Ready!', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05) | |
showMessage = False | |
count = 0 | |
try: | |
while True: | |
if showMessage == True: | |
show_message(device, telegramText, fill="white", font=proportional(LCD_FONT), scroll_delay=0.1) | |
count = count + 1 | |
if count == 3: | |
count = 0 | |
showMessage = False | |
else: | |
with canvas(virtual) as draw: | |
#text(draw, (0, 1), "Idris", fill="white", font=proportional(CP437_FONT)) | |
text(draw, (0, 1), datetime.now().strftime('%I:%M'), fill="white", font=proportional(CP437_FONT)) | |
except KeyboardInterrupt: | |
show_message(device, 'Thanks...', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment