Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 8x5 font text print feature to pcd8544.py #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pcd8544.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,36 @@ def fill_rect(self, x, y, w, h, col):

def show(self):
self.data(self.buf)

# for clearer and smaller text.
# It uses the same 8x5 font as used in arduino libraries
# the file font8x5.bin stores 5 bytes of data (for 5 pixels wide characters)
# for each of 96 ASCII characters starting from character ' ' (ASCII code 32).
# font8x5.bin can be found here :
# https://github.com/carrardt/TiPiDuino/raw/refs/heads/main/tools/bitmap/font8x5.bin
# Note: text printed with println function scrolls,
# thanks to screen member storing previous text lines
class PCD8544_BM8x5(PCD8544):
def __init__(self, spi, cs, dc, rst=None):
super().__init__(spi, cs, dc, rst)
self.font8x5 = open('font8x5.bin','rb').read()
self.screen = []

def text(self, col, row, s):
self.position(col,row)
for c in s:
ci = (ord(c)-ord(' '))*5
if (ci+5)>len(self.font8x5): ci = 0
cbm=bytearray(self.font8x5[ci:ci+5])
cbm.append(0x00)
self.data(cbm)

def println(self,s):
if len(self.screen)>=6:
self.screen.pop(0)
self.screen.append(s[:14])
r=0
self.clear()
for l in self.screen:
self.text(0,r,l)
r=r+1