Created
January 28, 2021 19:49
-
-
Save phjardas/8d47b61ae7ec4d6904557f8d75c7db78 to your computer and use it in GitHub Desktop.
Telegram LED Matrix Display With Raspberry Pi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import logging | |
from luma.led_matrix.device import max7219 | |
from luma.core.interface.serial import spi, noop | |
from luma.core.render import canvas | |
from luma.core.virtual import viewport | |
from luma.core.legacy import text, show_message | |
from luma.core.legacy.font import proportional, CP437_FONT | |
from telegram import ChatAction | |
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters | |
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) | |
logger = logging.getLogger('matrix') | |
serial = spi(port=0, device=0, gpio=noop()) | |
device = max7219(serial, cascaded=4, block_orientation=-90, rotate=2) | |
updater = Updater(token='..........................') | |
dispatcher = updater.dispatcher | |
def start(update, context): | |
context.bot.send_message(chat_id=update.effective_chat.id, text="Enter text to show it on the matrix display") | |
start_handler = CommandHandler('start', start) | |
dispatcher.add_handler(start_handler) | |
def echo(update, context): | |
text = update.message.text | |
try: | |
logger.info('Displaying "%s"', text) | |
update.message.reply_text("Displaying: {0}".format(text)) | |
context.bot.send_chat_action(chat_id=update.effective_message.chat_id, action=ChatAction.TYPING) | |
show_message(device, text, fill="white", font=proportional(CP437_FONT), scroll_delay=0.1) | |
logger.info('Done "%s"', text) | |
update.message.reply_text("Done: {0}".format(text)) | |
except Exception as error: | |
logger.warn('Error displaying "%s": %s', text, error) | |
update.message.reply_text("Error: {0}".format(error)) | |
echo_handler = MessageHandler(Filters.text & (~Filters.command), echo) | |
dispatcher.add_handler(echo_handler) | |
updater.start_polling() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment