Skip to content

Adding MagTag example #101

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

Merged
merged 4 commits into from
Nov 22, 2020
Merged
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
68 changes: 68 additions & 0 deletions examples/display_text_magtag.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
"""
Basic display_text.label example script
adapted for use on MagTag.
"""
import time
import board
import displayio
import terminalio
from adafruit_display_text import label

# use built in display (PyPortal, PyGamer, PyBadge, CLUE, etc.)
# see guide for setting up external displays (TFT / OLED breakouts, RGB matrices, etc.)
# https://learn.adafruit.com/circuitpython-display-support-using-displayio/display-and-display-bus
display = board.DISPLAY

# wait until we can draw
time.sleep(display.time_to_refresh)

# main group to hold everything
main_group = displayio.Group()

# white background. Scaled to save RAM
bg_bitmap = displayio.Bitmap(display.width // 8, display.height // 8, 1)
bg_palette = displayio.Palette(1)
bg_palette[0] = 0xFFFFFF
bg_sprite = displayio.TileGrid(bg_bitmap, x=0, y=0, pixel_shader=bg_palette)
bg_group = displayio.Group(scale=8)
bg_group.append(bg_sprite)
main_group.append(bg_group)

# first example label
TEXT = "Hello world"
text_area = label.Label(
terminalio.FONT,
text=TEXT,
color=0xFFFFFF,
background_color=0x666666,
padding_top=1,
padding_bottom=3,
padding_right=4,
padding_left=4,
)
text_area.x = 10
text_area.y = 14
main_group.append(text_area)

# second example label
another_text = label.Label(
terminalio.FONT,
scale=2,
text="MagTag display_text\nexample",
color=0x000000,
background_color=0x999999,
padding_top=1,
padding_bottom=3,
padding_right=4,
padding_left=4,
)
# centered
another_text.anchor_point = (0.5, 0.5)
another_text.anchored_position = (display.width // 2, display.height // 2)
main_group.append(another_text)

# show the main group and refresh.
display.show(main_group)
display.refresh()
while True:
pass