import time
time.sleep(1) # Wait for USB to become ready
"""ILI9341 demo (clear)."""
from time import sleep, ticks_ms
from ili9341 import Display, color656
from machine import Pin, SPI # type: ignore
import gc
colors = {
"RED": (255, 0, 0),
"GREEN": (0, 255, 0),
"BLUE": (0, 0, 255),
"YELLOW": (255, 255, 0),
"AQUA": (0, 255, 255),
"MAROON": (128, 0, 0),
"DARK_GREEN": (0, 128, 0),
"NAVY": (0, 0, 128),
"TEAL": (0, 128, 128),
"PURPLE": (128, 0, 128),
"ORANGE": (255, 128, 0),
"DEEP_PINK": (255, 0, 128),
"CYAN": (128, 255, 255),
}
def display_Init():
# Baud rate of 40000000 seems about the max
"""global spi
global display
global x_center
global y_center"""
spi = SPI(0, baudrate=40_000_000)
display = Display(spi, dc=Pin(15), cs=Pin(13), rst=Pin(14))
x_center = display.width // 2
y_center = display.height // 2
def test():
"""Test code."""
display.draw_text8x8(0, 0, 'Built-in', color565(255, 0, 255))
display.draw_text8x8(16, 16, 'MicroPython', color565(255, 255, 0))
display.draw_text8x8(32, 32, '8x8 Font', color565(0, 0, 255))
display.draw_text8x8(0, y_center - 44, "Rotate = 90",
color565(255, 0, 0), rotate=90)
display.draw_text8x8(x_center - 48, display.height - 9, "Rotate = 180",
color565(0, 255, 255), rotate=180)
display.draw_text8x8(display.width - 9, y_center - 48, "Rotate = 270",
color565(255, 255, 255), rotate=270)
display.draw_text8x8(x_center - 40, 140, "Rotate = 0",
color565(0, 255, 0), background=color565(255, 0, 0))
display.draw_text8x8(20, y_center - 44, "Rotate = 90", color565(255, 0, 0),
rotate=90, background=color565(0, 255, 0))
display.draw_text8x8(x_center - 48, display.height - 29, "Rotate = 180",
color565(0, 255, 255), rotate=180,
background=color565(0, 0, 255))
display.draw_text8x8(display.width - 29, y_center - 48, "Rotate = 270",
color565(255, 255, 255), rotate=270,
background=color565(255, 0, 255))
sleep(5)
#display.cleanup()
# Calculate valid hlines parameters for display clear method
valid_hlines = []
for i in range(1, display.height):
if display.height % i == 0:
valid_hlines.append(i)
# Ensure only 13 entries, truncate or repeat the last one
valid_hlines = valid_hlines[:13]
if len(valid_hlines) < 13:
valid_hlines += [valid_hlines[-1]] * (13 - len(valid_hlines))
# Ensure only 13 entries, truncate or repeat the last one
valid_hlines = valid_hlines[:13]
if len(valid_hlines) < 13:
valid_hlines += [valid_hlines[-1]] * (13 - len(valid_hlines))
print('Clearing to black...')
start = ticks_ms()
display.clear()
end = ticks_ms()
print(f'Display cleared in {end - start} ms.')
sleep(2)
print('Clearing to white...')
start = ticks_ms()
display.clear(color565(255, 255, 255))
end = ticks_ms()
print(f'Display cleared in {end - start} ms.')
sleep(2)
for hlines, (color, rgb) in zip(valid_hlines, colors.items()):
gc.collect()
print(f'Clearing display to {color}, hlines={hlines}...')
try:
start = ticks_ms()
display.clear(hlines=hlines, color=color565(*rgb))
end = ticks_ms()
print(f'Display cleared in {end - start} ms.')
except Exception as e:
print(e)
sleep(1)
sleep(5)
display.cleanup()
display_Init()
print("Hello, Pi Pico W!")
test()
print("Mehmet")
yazi = "Mehmet Bilgi"
uzunluk = int(len(yazi) * 4)
yukseklik = 8 #font yuksekligi burada 8
for i, (color, rgb) in zip(range(30), colors.items()):
display.draw_text8x8(x_center - uzunluk, display.height - (i * (yukseklik + 1)), yazi, color565(*rgb), rotate = 180)