Skip to content

Instantly share code, notes, and snippets.

@Tamakichi
Created March 14, 2024 06:14
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 Tamakichi/3c2b5732bc3c52fcc963cfae0c602fc2 to your computer and use it in GitHub Desktop.
Save Tamakichi/3c2b5732bc3c52fcc963cfae0c602fc2 to your computer and use it in GitHub Desktop.
MAX7219 LEDドットマトリックスで美咲フォントを利用したメッセージ表示
from machine import Pin, SPI
from device.max7219 import Matrix8x8
from time import sleep, sleep_ms
from misakifont import MisakiFont
# メッセージボード
class MessageBoard(Matrix8x8):
# コンストラクタ
def __init__(self, spi, cs, num):
super().__init__(spi, cs, num)
self.text = self.__text__
self.misaki = MisakiFont()
self.width = num * 8
self.height = 8
# フォント表示
def drowFont(self, font, x, y, fw=8, c=1):
for px in range(fw):
for py in range(8):
self.pixel(x+px, y+py, c if font[py] & (0x80>>px) else not c)
# テキスト表示
def __text__(self, msg, x, y, c=1, sw=1):
for char in msg:
code = ord(char)
fw = 8 if self.misaki.isZenkaku(code) else 4
font = self.misaki.font(code,False)
self.drowFont(font, x, y, fw, c)
x+=fw
if sw:
self.show()
# 1文字左スクロール挿入
def scrollIn(self, fnt, color=1, tm=100, ypos=0, fw=8, fh=8):
for i in range(0,fw):
self.scroll(-1,0)
for j in range(0,fh): # フォントパターン1列分のセット
self.pixel(self.width-1,j+ypos, color if fnt[j] & (0x80 >> i) else not color)
self.show()
sleep_ms(tm)
# テキストのスクロール表示
def messgae(self, msg, color=1, tm=100, ypos=0):
for c in msg:
font = self.misaki.font(ord(c),False)
self.scrollIn(font,color,tm,ypos, 8 if self.misaki.isZenkaku(ord(c)) else 4)
def cls(self):
self.fill(0)
from machine import Pin, SPI
from device.messageboard import MessageBoard
from time import sleep, sleep_ms
# メッセージボード インスタンス生成
spi = SPI(0,sck=Pin(2),mosi=Pin(3))
cs = Pin(5, Pin.OUT)
board = MessageBoard(spi, cs, 4)
board.brightness(1)
while True:
# 文字の表示
board.cls()
board.text("日本語の", 0, 1)
sleep(2)
board.cls()
board.text("表示デモ", 0, 1)
sleep(2)
board.cls()
board.text("です!", 6, 0)
sleep(2)
# 縦スクロール
for i in range(board.height):
board.scroll(0,-1)
board.show()
sleep_ms(100)
# 文字のスクロール表示
board.cls()
board.messgae("12abcこんにちは,世界!コンニチハサイタマ!",1,100,1)
sleep_ms(1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment