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