From c38baeb932534212cea952ee421c38ca3c97537f Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 22 Nov 2020 15:01:06 -0600 Subject: [PATCH 1/2] adding magtag example --- examples/bitmap_font_label_magtag.py | 43 ++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 examples/bitmap_font_label_magtag.py diff --git a/examples/bitmap_font_label_magtag.py b/examples/bitmap_font_label_magtag.py new file mode 100644 index 0000000..2aa8645 --- /dev/null +++ b/examples/bitmap_font_label_magtag.py @@ -0,0 +1,43 @@ +""" +This example uses addfruit_display_text.label to display text using a custom font +loaded by adafruit_bitmap_font. +Adapted for use on MagTag +""" +import time +import board +from adafruit_display_text import label +from adafruit_bitmap_font import bitmap_font + +# 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 +time.sleep(display.time_to_refresh) + +# Set text, font, and color +text = "HELLO WORLD\nbitmap_font example" +font = bitmap_font.load_font("fonts/Arial-16.bdf") +color = 0xFFFFFF +background_color = 0x999999 + +# Create the tet label +text_area = label.Label( + font, + text=text, + color=color, + background_color=background_color, + padding_top=3, + padding_bottom=3, + padding_right=4, + padding_left=4, +) +text_area.line_spacing = 1.0 +# Set the location +text_area.x = 20 +text_area.y = 20 + +# Show it +display.show(text_area) +display.refresh() +while True: + pass From 8c1fa9b6847f8038ea18eed36d8577f7c06a30a1 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 22 Nov 2020 15:04:12 -0600 Subject: [PATCH 2/2] a few comments in magtag example --- examples/bitmap_font_label_magtag.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/bitmap_font_label_magtag.py b/examples/bitmap_font_label_magtag.py index 2aa8645..e6685b2 100644 --- a/examples/bitmap_font_label_magtag.py +++ b/examples/bitmap_font_label_magtag.py @@ -12,6 +12,7 @@ # 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 refresh the display time.sleep(display.time_to_refresh) # Set text, font, and color @@ -36,7 +37,7 @@ text_area.x = 20 text_area.y = 20 -# Show it +# Show it and refresh display.show(text_area) display.refresh() while True: