Skip to content

Instantly share code, notes, and snippets.

@IdrisCytron
Last active May 31, 2019 04:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IdrisCytron/364176797c4a286e16ccead714261cbf to your computer and use it in GitHub Desktop.
Save IdrisCytron/364176797c4a286e16ccead714261cbf to your computer and use it in GitHub Desktop.
Displaying text on MAX7219 dot matrix from Blynk app.
from gpiozero import LED, Button, Buzzer
import BlynkLib
from time import time, sleep, strftime
from datetime import datetime
import sys
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
led1 = LED(17)
led2 = LED(18)
led3 = LED(27)
led4 = LED(22)
led5 = LED(25)
led6 = LED(12)
led7 = LED(13)
led8 = LED(19)
sw1 = Button(21)
buzzer = Buzzer(26)
BLYNK_AUTH = 'YourAuthToken'
# Initialize Blynk
blynk = BlynkLib.Blynk(BLYNK_AUTH)
# Register Virtual Pins
@blynk.VIRTUAL_WRITE(0)
def my_write_handler(value):
global counter
global BlynkText
buzzer.beep(0.1, 0.1, 1)
BlynkText = format(value[0])
print('Blynk Text: {}'.format(BlynkText))
counter = 1
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=8)
def millis():
return time() * 1000
def my_user_task():
global counter
global BlynkText
print('Counter = {}'.format(counter))
if counter == 0:
buzzer.beep(0.1, 0.1, 2)
show_message(device, 'Blynk Ready', fill="white", font=proportional(LCD_FONT), scroll_delay=0.05)
counter = 3
elif counter < 4:
if len(BlynkText) > 0:
show_message(device, BlynkText, fill="white", font=proportional(LCD_FONT), scroll_delay=0.08)
else:
counter = 3
else:
if counter == 10:
counter = 0
with canvas(virtual) as draw:
text(draw, (0, 1), datetime.now().strftime('%I:%M'), fill="white", font=proportional(CP437_FONT))
counter = counter + 1
counter = 0
BlynkText = ''
currentMillis = 0
previousMillis = 0
interval = 5000
try:
while True:
blynk.run()
currentMillis = millis()
if currentMillis - previousMillis > interval:
my_user_task()
previousMillis = currentMillis
except KeyboardInterrupt:
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment