import time
from machine import Pin, SPI
import ili9341
# --- SPI + Display Setup ---
spi = SPI(1, baudrate=40000000, sck=Pin(14), mosi=Pin(13), miso=Pin(12))
display = ili9341.ILI9341(spi, cs=Pin(15), dc=Pin(2), rst=Pin(4))
# --- Demo Functions ---
def demo_fill():
display.fill_screen(ili9341.color565(255, 0, 0)) # Red
time.sleep(1)
display.fill_screen(ili9341.color565(0, 255, 0)) # Green
time.sleep(1)
display.fill_screen(ili9341.color565(0, 0, 255)) # Blue
time.sleep(1)
def demo_text():
display.fill_screen(0)
display.set_pos(20, 40)
display.print("Hello ESP32!", ili9341.color565(0, 255, 0))
time.sleep(2)
def demo_shapes():
display.fill_screen(0)
display.draw_rectangle(50, 50, 100, 100, ili9341.color565(0, 0, 255))
display.draw_circle(160, 120, 40, ili9341.color565(255, 255, 0))
time.sleep(2)
def demo_gradient():
for y in range(240):
color = ili9341.color565(y, 0, 255-y)
display.draw_hline(0, y, 320, color)
time.sleep(2)
def demo_animation():
x = 0
for _ in range(30): # Run 30 frames
display.fill_screen(0)
display.draw_rectangle(x, 100, 50, 50, ili9341.color565(255, 0, 255))
x = (x + 10) % 320
time.sleep(0.1)
# --- Main Loop ---
while True:
demo_fill()
demo_text()
demo_shapes()
demo_gradient()
demo_animation()
https://wokwi.com/projects/new/micropython-esp32-s3