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