Skip to content

Commit 714a535

Browse files
committed
better error catching if no font, display hello world properly
1 parent 4582f83 commit 714a535

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

examples/ssd1306_framebuftest.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,20 @@
6767

6868
print("Text test")
6969
display.fill(0)
70-
display.text('hello world', 0, 0, 1)
71-
char_width = 6
72-
char_height = 8
73-
chars_per_line = display.width//6
74-
for i in range(255):
75-
x = char_width * (i % chars_per_line)
76-
y = char_height * (i // chars_per_line)
77-
display.text(chr(i), x, y, 1)
78-
display.show()
70+
try:
71+
display.text('hello world', 0, 0, 1)
72+
display.show()
73+
time.sleep(1)
74+
display.fill(0)
75+
char_width = 6
76+
char_height = 8
77+
chars_per_line = display.width//6
78+
for i in range(255):
79+
x = char_width * (i % chars_per_line)
80+
y = char_height * (i // chars_per_line)
81+
display.text(chr(i), x, y, 1)
82+
display.show()
83+
except FileNotFoundError:
84+
print("To test the framebuf font setup, you'll need the font5x8.bin file from " +
85+
"https://github.com/adafruit/Adafruit_CircuitPython_framebuf/tree/master/examples" +
86+
" in the same directory as this script")

0 commit comments

Comments
 (0)