-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo_fonts.py
56 lines (43 loc) · 1.79 KB
/
demo_fonts.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""SSD1322 demo (fonts)."""
from time import sleep
from machine import Pin, SPI # type: ignore
from xglcd_font import XglcdFont
from ssd1322 import Display
def test():
"""Test code."""
spi = SPI(0, baudrate=25000000, sck=Pin(18), mosi=Pin(19))
display = Display(spi, dc=Pin(20), cs=Pin(17), rst=Pin(21))
print("Loading fonts. Please wait.")
bally = XglcdFont('fonts/Bally7x9.c', 7, 9)
rototron = XglcdFont('fonts/Robotron13x21.c', 13, 21)
unispace = XglcdFont('fonts/Unispace12x24.c', 12, 24)
wendy = XglcdFont('fonts/Wendy7x8.c', 7, 8)
print("Drawing fonts.")
text_height = bally.height
display.draw_text(display.width, display.height // 2 - text_height // 2,
"Bally", bally, rotate=180)
text_width = rototron.measure_text("ROTOTRON")
display.draw_text(display.width // 2 - text_width // 2, 0,
"ROTOTRON", rototron)
text_width = unispace.measure_text("Unispace", spacing=3)
text_height = unispace.height
display.draw_text(display.width // 2 - text_width // 2,
display.height - text_height,
"Unispace", unispace, invert=True, spacing=3)
text_width = wendy.measure_text("Wendy")
display.draw_text(0, display.height // 2 - text_width // 2,
"Wendy", wendy, rotate=90)
display.draw_text(15, display.height // 2 + text_width // 2,
"Wendy", wendy, rotate=270)
pos = 50
text_height = bally.height
for c in range(1, 16):
text_width = bally.measure_text(str(c))
display.draw_text(pos, display.height // 2 - text_height, str(c),
bally, invert=True, gs=c)
pos += text_width + 1
display.present()
sleep(15)
display.cleanup()
print('Done.')
test()