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