rgb_display_ili9341test.py
1 # Quick test of TFT FeatherWing (ILI9341) 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 busio 7 import digitalio 8 import board 9 10 from adafruit_rgb_display.rgb import color565 11 import adafruit_rgb_display.ili9341 as ili9341 12 13 14 # Configuratoin for CS and DC pins (these are FeatherWing defaults on M0/M4): 15 cs_pin = digitalio.DigitalInOut(board.D9) 16 dc_pin = digitalio.DigitalInOut(board.D10) 17 18 # Config for display baudrate (default max is 24mhz): 19 BAUDRATE = 24000000 20 21 # Setup SPI bus using hardware SPI: 22 spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) 23 24 # Create the ILI9341 display: 25 display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_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)