micropython-st7789py-lcd-dr.../examples/ttgo_tdisplay/lines.py

65 wiersze
1.4 KiB
Python

"""
lines.py
Draws lines and rectangles in random colors at random locations on the
display.
"""
import random
from machine import Pin, SoftSPI
import st7789py as st7789
def main():
spi = SoftSPI(
baudrate=20000000,
polarity=1,
phase=0,
sck=Pin(18),
mosi=Pin(19),
miso=Pin(13))
tft = st7789.ST7789(
spi,
135,
240,
reset=Pin(23, Pin.OUT),
cs=Pin(5, Pin.OUT),
dc=Pin(16, Pin.OUT),
backlight=Pin(4, Pin.OUT),
rotation=0)
tft.fill(st7789.BLACK)
while True:
tft.line(
random.randint(0, tft.width),
random.randint(0, tft.height),
random.randint(0, tft.width),
random.randint(0, tft.height),
st7789.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8)
)
)
width = random.randint(0, tft.width // 2)
height = random.randint(0, tft.height // 2)
col = random.randint(0, tft.width - width)
row = random.randint(0, tft.height - height)
tft.fill_rect(
col,
row,
width,
height,
st7789.color565(
random.getrandbits(8),
random.getrandbits(8),
random.getrandbits(8)
)
)
main()