|
1 |
| -# Quick test of TFT FeatherWing (ILI9341) with ESP8266 Adafruit MicroPython. |
| 1 | +# Quick test of TFT FeatherWing (ILI9341) with Feather M0 or M4 |
2 | 2 | # Will fill the TFT black and put a red pixel in the center, wait 2 seconds,
|
3 | 3 | # then fill the screen blue (with no pixel), wait 2 seconds, and repeat.
|
4 | 4 | import time
|
5 |
| - |
| 5 | +import random |
6 | 6 | import busio
|
7 | 7 | import digitalio
|
8 |
| -from board import SCK, MOSI, MISO, GPIO0, GPIO15 |
| 8 | +import board |
9 | 9 |
|
10 |
| -from adafruit_rgb_display import color565 |
| 10 | +from adafruit_rgb_display.rgb import color565 |
11 | 11 | import adafruit_rgb_display.ili9341 as ili9341
|
12 | 12 |
|
13 | 13 |
|
14 |
| -# Configuratoin for CS and DC pins (these are FeatherWing defaults on ESP8266): |
15 |
| -CS_PIN = GPIO0 |
16 |
| -DC_PIN = GPIO15 |
17 |
| -# Config for display baudrate (default is 32mhz, about as fast as the ESP supports): |
18 |
| -BAUDRATE = 32000000 |
| 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) |
19 | 17 |
|
| 18 | +# Config for display baudrate (default max is 24mhz): |
| 19 | +BAUDRATE = 24000000 |
20 | 20 |
|
21 | 21 | # Setup SPI bus using hardware SPI:
|
22 |
| -spi = busio.SPI(clock=SCK, MOSI=MOSI, MISO=MISO) |
| 22 | +spi = busio.SPI(clock=board.SCK, MOSI=board.MOSI, MISO=board.MISO) |
23 | 23 |
|
24 | 24 | # Create the ILI9341 display:
|
25 |
| -display = ili9341.ILI9341(spi, cs=digitalio.DigitalInOut(CS_PIN), |
26 |
| - dc=digitalio.DigitalInOut(DC_PIN), baudrate=BAUDRATE) |
| 25 | +display = ili9341.ILI9341(spi, cs=cs_pin, dc=dc_pin, baudrate=BAUDRATE) |
27 | 26 |
|
28 | 27 | # Main loop:
|
29 | 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)) |
30 | 32 | # Clear the display
|
31 | 33 | display.fill(0)
|
32 | 34 | # Draw a red pixel in the center.
|
33 |
| - display.pixel(120, 160, color565(255, 0, 0)) |
| 35 | + display.pixel(display.width//2, display.height//2, color565(255, 0, 0)) |
34 | 36 | # Pause 2 seconds.
|
35 | 37 | time.sleep(2)
|
36 |
| - # Clear the screen blue. |
37 |
| - display.fill(color565(0, 0, 255)) |
| 38 | + # Clear the screen a random color |
| 39 | + display.fill(color565(random.randint(0, 255), |
| 40 | + random.randint(0, 255), |
| 41 | + random.randint(0, 255))) |
38 | 42 | # Pause 2 seconds.
|
39 | 43 | time.sleep(2)
|
0 commit comments