Last active
July 23, 2019 14:25
-
-
Save izzuddin91/9a21b9f2d42a1c698475b88973d30592 to your computer and use it in GitHub Desktop.
7 segemend LED matrix
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 | |
# -*- coding: utf-8 -*- | |
# Copyright (c) 2017-18 Richard Hull and contributors | |
# See LICENSE.rst for details. | |
import re | |
import time | |
import argparse | |
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, TINY_FONT, SINCLAIR_FONT, LCD_FONT | |
def demo(n, block_orientation, rotate): | |
# create matrix device | |
serial = spi(port=0, device=0, gpio=noop()) | |
# kalau ade 1 x 4 led matrix, dalam func demo(), replace with this line | |
device = max7219(serial, block_orientation=-90, rotate=rotate or 0, width=32, height=8) | |
print("Created device") | |
# start demo | |
msg = "LED Matrix Demo" | |
print(msg) | |
show_message(device, msg, fill="white", font=proportional(CP437_FONT)) | |
time.sleep(1) | |
msg = "4 - coach train to gombak will arrive within 4 minutes" | |
print(msg) | |
show_message(device, msg, fill="white", font=proportional(CP437_FONT)) | |
time.sleep(1) | |
msg = "Selamat Datang ke Kedai Dobi Pak Ali" | |
print(msg) | |
show_message(device, msg, fill="white", font=proportional(CP437_FONT)) | |
time.sleep(1) | |
time.sleep(1) | |
for x in range(256): | |
with canvas(device) as draw: | |
text(draw, (0, 0), chr(x), fill="white") | |
time.sleep(0.1) | |
if __name__ == "__main__": | |
parser = argparse.ArgumentParser(description='matrix_demo arguments', | |
formatter_class=argparse.ArgumentDefaultsHelpFormatter) | |
parser.add_argument('--cascaded', '-n', type=int, default=1, help='Number of cascaded MAX7219 LED matrices') | |
parser.add_argument('--block-orientation', type=int, default=0, choices=[0, 90, -90], help='Corrects block orientation when wired vertically') | |
parser.add_argument('--rotate', type=int, default=0, choices=[0, 1, 2, 3], help='Rotate display 0=0°, 1=90°, 2=180°, 3=270°') | |
args = parser.parse_args() | |
try: | |
demo(args.cascaded, args.block_orientation, args.rotate) | |
except KeyboardInterrupt: | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment