Created
November 27, 2018 07:06
-
-
Save IdrisCytron/03423782af34fe31f51aa59efd05c3a2 to your computer and use it in GitHub Desktop.
Displaying Telegram text on MAX7219 dot matrix using Raspberry Pi.
This file contains 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
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
hello, I have a question for you. I would like to do the same thing but with a 16x2 or 20x4 LCD screen with ic2 connection on my raspberry. Do you think it's possible to modify the code? Thank you in advance for your reply .