|
| 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 native displayio modules. |
| 5 | +
|
| 6 | +Pinouts are for the 2.8" TFT Shield |
| 7 | +""" |
| 8 | +import board |
| 9 | +import displayio |
| 10 | +import terminalio |
| 11 | +import adafruit_ili9341 |
| 12 | + |
| 13 | +spi = board.SPI() |
| 14 | +tft_cs = board.D10 |
| 15 | +tft_dc = board.D9 |
| 16 | + |
| 17 | +displayio.release_displays() |
| 18 | +display_bus = displayio.FourWire(spi, command=tft_dc, chip_select=tft_cs) |
| 19 | +display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240) |
| 20 | + |
| 21 | +# Make the display context |
| 22 | +splash = displayio.Group(max_size=10) |
| 23 | +display.show(splash) |
| 24 | + |
| 25 | +# Draw a green background |
| 26 | +color_bitmap = displayio.Bitmap(320, 240, 1) |
| 27 | +color_palette = displayio.Palette(1) |
| 28 | +color_palette[0] = 0x00FF00 # Bright Green |
| 29 | + |
| 30 | +bg_sprite = displayio.TileGrid(color_bitmap, |
| 31 | + pixel_shader=color_palette, |
| 32 | + x=0, y=0) |
| 33 | + |
| 34 | +splash.append(bg_sprite) |
| 35 | + |
| 36 | +# Draw a smaller inner rectangle |
| 37 | +inner_bitmap = displayio.Bitmap(280, 200, 1) |
| 38 | +inner_palette = displayio.Palette(1) |
| 39 | +inner_palette[0] = 0x65328F # Blinka Purple |
| 40 | +inner_sprite = displayio.TileGrid(inner_bitmap, |
| 41 | + pixel_shader=inner_palette, |
| 42 | + x=20, y=20) |
| 43 | +splash.append(inner_sprite) |
| 44 | + |
| 45 | +# Draw some text the manual way! |
| 46 | +font_palette = displayio.Palette(2) |
| 47 | +font_palette.make_transparent(0) |
| 48 | +font_palette[1] = 0xFFFF00 # Yellow |
| 49 | + |
| 50 | +text_group = displayio.Group(max_size=20, scale=3, x=57, y=120) |
| 51 | +text = "Hello World!" |
| 52 | +x = 0 |
| 53 | + |
| 54 | +for character in text: |
| 55 | + glyph = terminalio.FONT.get_glyph(ord(character)) |
| 56 | + position_x = x + glyph.dx |
| 57 | + position_y = 0 - round((glyph.height - glyph.dy) / 2) # Center text vertically |
| 58 | + face = displayio.TileGrid(glyph.bitmap, pixel_shader=font_palette, |
| 59 | + default_tile=glyph.tile_index, |
| 60 | + tile_width=glyph.width, tile_height=glyph.height, |
| 61 | + x=position_x, y=position_y) |
| 62 | + text_group.append(face) |
| 63 | + x += glyph.shift_x |
| 64 | + |
| 65 | +splash.append(text_group) |
| 66 | + |
| 67 | +while True: |
| 68 | + pass |
0 commit comments