Skip to content

Commit 51e9a1f

Browse files
authored
Merge pull request #30 from FoamyGuy/magtag_example
adding MagTag example
2 parents 7e15354 + 8c1fa9b commit 51e9a1f

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

examples/bitmap_font_label_magtag.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"""
2+
This example uses addfruit_display_text.label to display text using a custom font
3+
loaded by adafruit_bitmap_font.
4+
Adapted for use on MagTag
5+
"""
6+
import time
7+
import board
8+
from adafruit_display_text import label
9+
from adafruit_bitmap_font import bitmap_font
10+
11+
# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
12+
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
13+
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
14+
display = board.DISPLAY
15+
# wait until we can refresh the display
16+
time.sleep(display.time_to_refresh)
17+
18+
# Set text, font, and color
19+
text = "HELLO WORLD\nbitmap_font example"
20+
font = bitmap_font.load_font("fonts/Arial-16.bdf")
21+
color = 0xFFFFFF
22+
background_color = 0x999999
23+
24+
# Create the tet label
25+
text_area = label.Label(
26+
font,
27+
text=text,
28+
color=color,
29+
background_color=background_color,
30+
padding_top=3,
31+
padding_bottom=3,
32+
padding_right=4,
33+
padding_left=4,
34+
)
35+
text_area.line_spacing = 1.0
36+
# Set the location
37+
text_area.x = 20
38+
text_area.y = 20
39+
40+
# Show it and refresh
41+
display.show(text_area)
42+
display.refresh()
43+
while True:
44+
pass

0 commit comments

Comments
 (0)