/ examples / rgb_display_simpletest.py
rgb_display_simpletest.py
 1  # Quick test of TFT FeatherWing (ST7789) with Feather M0 or M4
 2  # This will work even on a device running displayio
 3  # Will fill the TFT black and put a red pixel in the center, wait 2 seconds,
 4  # then fill the screen blue (with no pixel), wait 2 seconds, and repeat.
 5  import time
 6  import random
 7  import digitalio
 8  import board
 9  
10  from adafruit_rgb_display.rgb import color565
11  import adafruit_rgb_display.st7789 as st7789
12  
13  # Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4):
14  cs_pin = digitalio.DigitalInOut(board.D5)
15  dc_pin = digitalio.DigitalInOut(board.D6)
16  reset_pin = digitalio.DigitalInOut(board.D9)
17  
18  # Config for display baudrate (default max is 24mhz):
19  BAUDRATE = 24000000
20  
21  # Setup SPI bus using hardware SPI:
22  spi = board.SPI()
23  
24  # Create the ST7789 display:
25  display = st7789.ST7789(spi, cs=cs_pin, dc=dc_pin, rst=reset_pin, baudrate=BAUDRATE)
26  
27  # Main loop:
28  while True:
29      # Fill the screen red, green, blue, then black:
30      for color in ((255, 0, 0), (0, 255, 0), (0, 0, 255)):
31          display.fill(color565(color))
32      # Clear the display
33      display.fill(0)
34      # Draw a red pixel in the center.
35      display.pixel(display.width // 2, display.height // 2, color565(255, 0, 0))
36      # Pause 2 seconds.
37      time.sleep(2)
38      # Clear the screen a random color
39      display.fill(
40          color565(random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
41      )
42      # Pause 2 seconds.
43      time.sleep(2)