|
| 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. All drawing is done |
| 4 | +using the displayio module. |
| 5 | +
|
| 6 | +Pinouts are for the PiTFT and should be run in CPython. |
| 7 | +""" |
| 8 | +import board |
| 9 | +import terminalio |
| 10 | +import displayio |
| 11 | +from adafruit_display_text import label |
| 12 | +import adafruit_ili9341 |
| 13 | + |
| 14 | +# Release any resources currently in use for the displays |
| 15 | +displayio.release_displays() |
| 16 | + |
| 17 | +spi = board.SPI() |
| 18 | +tft_cs = board.CE0 |
| 19 | +tft_dc = board.D25 |
| 20 | + |
| 21 | +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) |
| 22 | +display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240) |
| 23 | + |
| 24 | +# Make the display context |
| 25 | +splash = displayio.Group(max_size=10) |
| 26 | +display.show(splash) |
| 27 | + |
| 28 | +# Draw a green background |
| 29 | +color_bitmap = displayio.Bitmap(display.width, display.height, 1) |
| 30 | +color_palette = displayio.Palette(1) |
| 31 | +color_palette[0] = 0x00FF00 # Bright Green |
| 32 | + |
| 33 | +bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0) |
| 34 | + |
| 35 | +splash.append(bg_sprite) |
| 36 | + |
| 37 | +# Draw a smaller inner rectangle |
| 38 | +inner_bitmap = displayio.Bitmap(display.width - 40, display.height - 40, 1) |
| 39 | +inner_palette = displayio.Palette(1) |
| 40 | +inner_palette[0] = 0xAA0088 # Purple |
| 41 | +inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20) |
| 42 | +splash.append(inner_sprite) |
| 43 | + |
| 44 | +# Draw a label |
| 45 | +text_group = displayio.Group(max_size=10, scale=3, x=57, y=120) |
| 46 | +text = "Hello World!" |
| 47 | +text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00) |
| 48 | +text_group.append(text_area) # Subgroup for text scaling |
| 49 | +splash.append(text_group) |
| 50 | + |
| 51 | +while True: |
| 52 | + pass |
0 commit comments