########################################
# IMPORT LIBRARIES
########################################
import machine
from utime import sleep
from ili9341 import Display, color565
from xglcd_font import XglcdFont
########################################
# PIN CONFIGURATIONS
########################################
# Configure the SPI pin
# Replace the x with SCK Pin x number here
sck = machine.Pin(18)
# Replace the y with MOSI Pin y number here
mosi = machine.Pin(23)
# Replace the z with MISO Pin z number here
miso = machine.Pin(19)
# SPI configuration
spi = machine.SPI(1, baudrate=32000000, sck=sck, mosi=mosi, miso=miso)
# Use SPI with devices:
# Replace the x with GPIO Pin t number here
cs = machine.Pin(15)
# Replace the y with GPIO Pin u number here
dc = machine.Pin(0)
# Replace the x with CS Pin x number here
rst = machine.Pin(2)
display = Display(spi, dc=dc, cs=cs, rst=rst)
arcadepix = XglcdFont('ArcadePix9x11.c', 9, 11)
########################################
# MAIN ROUTINE
########################################
def main():
while True:
# Subroutine here
ili9341_spi()
#############################################
############### SUBROUTINES #################
#############################################
def ili9341_spi():
display.clear(color565(64, 0, 255))
sleep(1)
display.clear()
display.draw_hline(10, 319, 229, color565(255, 0, 255))
sleep(1)
display.draw_vline(10, 0, 319, color565(0, 255, 255))
sleep(1)
display.fill_hrect(23, 50, 30, 75, color565(255, 255, 255))
sleep(1)
display.draw_hline(0, 0, 222, color565(255, 0, 0))
sleep(1)
display.draw_line(127, 0, 64, 127, color565(255, 255, 0))
sleep(2)
display.clear()
coords = [[0, 63], [78, 80], [122, 92], [50, 50], [78, 15], [0, 63]]
display.draw_lines(coords, color565(0, 255, 255))
sleep(1)
display.clear()
display.fill_polygon(7, 120, 120, 100, color565(0, 255, 0))
sleep(1)
display.fill_rectangle(0, 0, 15, 227, color565(255, 0, 0))
sleep(1)
display.clear()
display.fill_rectangle(0, 0, 163, 163, color565(128, 128, 255))
sleep(1)
display.draw_rectangle(0, 64, 163, 163, color565(255, 0, 255))
sleep(1)
display.fill_rectangle(64, 0, 163, 163, color565(128, 0, 255))
sleep(1)
display.draw_polygon(3, 120, 286, 30, color565(0, 64, 255), rotate=15)
sleep(3)
display.clear()
display.fill_circle(132, 132, 70, color565(0, 255, 0))
sleep(1)
display.draw_circle(132, 96, 70, color565(0, 0, 255))
sleep(1)
display.fill_ellipse(96, 96, 30, 16, color565(255, 0, 0))
sleep(1)
display.draw_ellipse(96, 256, 16, 30, color565(255, 255, 0))
sleep(5)
display.clear()
text = "Welcome to ETC613!"
display.draw_text(
x=0,
y=0,
text=text,
font=arcadepix,
color=color565(255, 0, 0),
background=color565(255, 255, 255),
landscape=False,
spacing=1
)
sleep(5)
display.clear()
#############################################
############# EXECUTE MAIN ROUTINE ##########
#############################################
if __name__ == "__main__":
main()