|
| 1 | +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | + |
| 4 | +""" |
| 5 | +This test will initialize the display using displayio and draw a solid green |
| 6 | +background, a smaller purple rectangle, and some yellow text. |
| 7 | +""" |
| 8 | +import board |
| 9 | +import terminalio |
| 10 | +import displayio |
| 11 | +from adafruit_display_text import label |
| 12 | +from adafruit_st7789 import ST7789 |
| 13 | + |
| 14 | +BORDER_WIDTH = 20 |
| 15 | +TEXT_SCALE = 3 |
| 16 | + |
| 17 | +# Release any resources currently in use for the displays |
| 18 | +displayio.release_displays() |
| 19 | + |
| 20 | +spi = board.SPI() |
| 21 | +tft_cs = board.D5 |
| 22 | +tft_dc = board.D6 |
| 23 | +tft_rst = board.D9 |
| 24 | + |
| 25 | +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs, reset=tft_rst) |
| 26 | + |
| 27 | +display = ST7789(display_bus, width=320, height=172, colstart=34, rotation=270) |
| 28 | + |
| 29 | +# Make the display context |
| 30 | +splash = displayio.Group() |
| 31 | +display.show(splash) |
| 32 | + |
| 33 | +color_bitmap = displayio.Bitmap(display.width, display.height, 1) |
| 34 | +color_palette = displayio.Palette(1) |
| 35 | +color_palette[0] = 0x00FF00 # Bright Green |
| 36 | +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) |
| 37 | +splash.append(bg_sprite) |
| 38 | + |
| 39 | +# Draw a smaller inner rectangle |
| 40 | +inner_bitmap = displayio.Bitmap( |
| 41 | + display.width - (BORDER_WIDTH * 2), display.height - (BORDER_WIDTH * 2), 1 |
| 42 | +) |
| 43 | +inner_palette = displayio.Palette(1) |
| 44 | +inner_palette[0] = 0xAA0088 # Purple |
| 45 | +inner_sprite = displayio.TileGrid( |
| 46 | + inner_bitmap, pixel_shader=inner_palette, x=BORDER_WIDTH, y=BORDER_WIDTH |
| 47 | +) |
| 48 | +splash.append(inner_sprite) |
| 49 | + |
| 50 | +# Draw a label |
| 51 | +text_area = label.Label( |
| 52 | + terminalio.FONT, |
| 53 | + text="Hello World!", |
| 54 | + color=0xFFFF00, |
| 55 | + scale=TEXT_SCALE, |
| 56 | + anchor_point=(0.5, 0.5), |
| 57 | + anchored_position=(display.width // 2, display.height // 2), |
| 58 | +) |
| 59 | +splash.append(text_area) |
| 60 | + |
| 61 | +while True: |
| 62 | + pass |
0 commit comments