|
| 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 busio |
| 7 | +import displayio |
| 8 | +import terminalio |
| 9 | +from adafruit_display_text import label |
| 10 | +from adafruit_st7789 import ST7789 |
| 11 | + |
| 12 | +# Release any resources currently in use for the displays |
| 13 | +displayio.release_displays() |
| 14 | + |
| 15 | +spi = busio.SPI(board.SCL, MOSI=board.SDA) |
| 16 | +tft_cs = board.RX |
| 17 | +tft_dc = board.TX |
| 18 | +tft_backlight = board.A3 |
| 19 | + |
| 20 | +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) |
| 21 | + |
| 22 | +display = ST7789(display_bus, width=240, height=240, rowstart=80, |
| 23 | + backlight_pin=tft_backlight, rotation=180) |
| 24 | + |
| 25 | +# Make the display context |
| 26 | +splash = displayio.Group(max_size=10) |
| 27 | +display.show(splash) |
| 28 | + |
| 29 | +color_bitmap = displayio.Bitmap(240, 240, 1) |
| 30 | +color_palette = displayio.Palette(1) |
| 31 | +color_palette[0] = 0x00FF00 # Bright Green |
| 32 | + |
| 33 | +bg_sprite = displayio.TileGrid(color_bitmap, |
| 34 | + pixel_shader=color_palette, |
| 35 | + x=0, y=0) |
| 36 | +splash.append(bg_sprite) |
| 37 | + |
| 38 | +# Draw a smaller inner rectangle |
| 39 | +inner_bitmap = displayio.Bitmap(200, 200, 1) |
| 40 | +inner_palette = displayio.Palette(1) |
| 41 | +inner_palette[0] = 0xAA0088 # Purple |
| 42 | +inner_sprite = displayio.TileGrid(inner_bitmap, |
| 43 | + pixel_shader=inner_palette, |
| 44 | + x=20, y=20) |
| 45 | +splash.append(inner_sprite) |
| 46 | + |
| 47 | +# Draw a label |
| 48 | +text_group = displayio.Group(max_size=10, scale=2, x=50, y=120) |
| 49 | +text = "Hello World!" |
| 50 | +text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00) |
| 51 | +text_group.append(text_area) # Subgroup for text scaling |
| 52 | +splash.append(text_group) |
| 53 | + |
| 54 | +while True: |
| 55 | + pass |
0 commit comments