/ examples / ili9341_simpletest.py
ili9341_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. All drawing is done
 4  using native displayio modules.
 5  
 6  Pinouts are for the 2.4" TFT FeatherWing or Breakout with a Feather M4 or M0.
 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.D9
19  tft_dc = board.D10
20  
21  display_bus = displayio.FourWire(
22      spi, command=tft_dc, chip_select=tft_cs, reset=board.D6
23  )
24  display = adafruit_ili9341.ILI9341(display_bus, width=320, height=240)
25  
26  # Make the display context
27  splash = displayio.Group(max_size=10)
28  display.show(splash)
29  
30  # Draw a green background
31  color_bitmap = displayio.Bitmap(320, 240, 1)
32  color_palette = displayio.Palette(1)
33  color_palette[0] = 0x00FF00  # Bright Green
34  
35  bg_sprite = displayio.TileGrid(color_bitmap, pixel_shader=color_palette, x=0, y=0)
36  
37  splash.append(bg_sprite)
38  
39  # Draw a smaller inner rectangle
40  inner_bitmap = displayio.Bitmap(280, 200, 1)
41  inner_palette = displayio.Palette(1)
42  inner_palette[0] = 0xAA0088  # Purple
43  inner_sprite = displayio.TileGrid(inner_bitmap, pixel_shader=inner_palette, x=20, y=20)
44  splash.append(inner_sprite)
45  
46  # Draw a label
47  text_group = displayio.Group(max_size=10, scale=3, x=57, y=120)
48  text = "Hello World!"
49  text_area = label.Label(terminalio.FONT, text=text, color=0xFFFF00)
50  text_group.append(text_area)  # Subgroup for text scaling
51  splash.append(text_group)
52  
53  while True:
54      pass