micropython-st7789py-lcd-dr.../examples/ttgo_tdisplay_rp2040/hello.py

76 wiersze
1.9 KiB
Python

"""
hello.py
Writes "Hello!" in random colors at random locations on a
LILYGO® TTGO T-Display.
https://www.youtube.com/watch?v=atBa0BYPAAc
"""
import random
from machine import Pin, SoftSPI
import st7789py as st7789
# Choose a font
# from romfonts import vga1_8x8 as font
# from romfonts import vga2_8x8 as font
# from romfonts import vga1_8x16 as font
# from romfonts import vga2_8x16 as font
# from romfonts import vga1_16x16 as font
# from romfonts import vga1_bold_16x16 as font
# from romfonts import vga2_16x16 as font
# from romfonts import vga2_bold_16x16 as font
# from romfonts import vga1_16x32 as font
# from romfonts import vga1_bold_16x32 as font
# from romfonts import vga2_16x32 as font
from romfonts import vga2_bold_16x32 as font
def main():
Pin(22, Pin.OUT, value=1)
spi = SoftSPI(
baudrate=20000000,
polarity=1,
phase=0,
sck=Pin(2),
mosi=Pin(3),
miso=Pin(13))
tft = st7789.ST7789(
spi,
135,
240,
reset=Pin(0, Pin.OUT),
cs=Pin(5, Pin.OUT),
dc=Pin(1, Pin.OUT),
backlight=Pin(4, Pin.OUT),
rotation=1)
while True:
for rotation in range(4):
tft.rotation(rotation)
tft.fill(0)
col_max = tft.width - font.WIDTH*6
row_max = tft.height - font.HEIGHT
for _ in range(100):
tft.text(
font,
"Hello!",
random.randint(0, col_max),
random.randint(0, row_max),
st7789.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8)),
st7789.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8))
)
main()