|
| 1 | +""" |
| 2 | +Simple text script for Adafruit 2.13" 212x104 tri-color display |
| 3 | +Supported products: |
| 4 | + * Adafruit 2.13" Tri-Color Display Breakout |
| 5 | + * Adafruit 2.13" Tri-Color Display FeatherWing |
| 6 | + https://www.adafruit.com/product/4086 (breakout) or |
| 7 | + https://www.adafruit.com/product/4128 (FeatherWing) |
| 8 | +
|
| 9 | + This program requires the adafruit_il0373 library and the |
| 10 | + adafruit_display_text library in the CIRCUITPY /lib folder |
| 11 | + for CircuitPython 5.0 and above which has displayio support. |
| 12 | +""" |
| 13 | + |
| 14 | +import time |
| 15 | +import board |
| 16 | +import displayio |
| 17 | +import adafruit_il0373 |
| 18 | +import terminalio |
| 19 | +from adafruit_display_text import label |
| 20 | + |
| 21 | +BLACK = 0x000000 |
| 22 | +WHITE = 0xFFFFFF |
| 23 | +RED = 0xFF0000 |
| 24 | + |
| 25 | +# Change text colors, choose from the following values: |
| 26 | +# BLACK, RED, WHITE |
| 27 | + |
| 28 | +FOREGROUND_COLOR = RED |
| 29 | +BACKGROUND_COLOR = WHITE |
| 30 | + |
| 31 | +# Used to ensure the display is free in CircuitPython |
| 32 | +displayio.release_displays() |
| 33 | + |
| 34 | +# Define the pins needed for display use |
| 35 | +# This pinout is for a Feather M4 and may be different for other boards |
| 36 | +spi = board.SPI() # Uses SCK and MOSI |
| 37 | +epd_cs = board.D9 |
| 38 | +epd_dc = board.D10 |
| 39 | +epd_reset = board.D5 |
| 40 | +epd_busy = board.D6 |
| 41 | + |
| 42 | +# Create the displayio connection to the display pins |
| 43 | +display_bus = displayio.FourWire(spi, command=epd_dc, chip_select=epd_cs, |
| 44 | + reset=epd_reset, baudrate=1000000) |
| 45 | +time.sleep(1) # Wait a bit |
| 46 | + |
| 47 | +# Create the display object - the third color is red (0xff0000) |
| 48 | +DISPLAY_WIDTH = 212 |
| 49 | +DISPLAY_HEIGHT = 104 |
| 50 | + |
| 51 | +display = adafruit_il0373.IL0373(display_bus, width=DISPLAY_WIDTH, |
| 52 | + height=DISPLAY_HEIGHT, |
| 53 | + rotation=90, busy_pin=epd_busy, |
| 54 | + highlight_color=0xff0000) |
| 55 | + |
| 56 | +# Create a display group for our screen objects |
| 57 | +g = displayio.Group(max_size=10) |
| 58 | + |
| 59 | +# Set a background |
| 60 | +background_bitmap = displayio.Bitmap(DISPLAY_WIDTH, DISPLAY_HEIGHT, 1) |
| 61 | +# Map colors in a palette |
| 62 | +palette = displayio.Palette(1) |
| 63 | +palette[0] = BACKGROUND_COLOR |
| 64 | + |
| 65 | +# Create a Tilegrid with the background and put in the displayio group |
| 66 | +t = displayio.TileGrid(background_bitmap, pixel_shader=palette) |
| 67 | +g.append(t) |
| 68 | + |
| 69 | +# Draw simple text using the built-in font into a displayio group |
| 70 | +text_group = displayio.Group(max_size=10, scale=2, x=20, y=40) |
| 71 | +text = "Hello World!" |
| 72 | +text_area = label.Label(terminalio.FONT, text=text, color=FOREGROUND_COLOR) |
| 73 | +text_group.append(text_area) # Add this text to the text group |
| 74 | +g.append(text_group) |
| 75 | + |
| 76 | +# Place the display group on the screen |
| 77 | +display.show(g) |
| 78 | + |
| 79 | +# Refresh the display to have everything show on the display |
| 80 | +# NOTE: Do not refresh eInk displays more often than 180 seconds! |
| 81 | +display.refresh() |
| 82 | + |
| 83 | +time.sleep(120) |
| 84 | + |
| 85 | +while True: |
| 86 | + pass |
0 commit comments