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

61 wiersze
1.3 KiB
Python
Czysty Zwykły widok Historia

"""
lines.py
Draws lines and rectangles in random colors at random locations on the
display.
"""
import random
2021-12-23 18:54:40 +00:00
from machine import Pin, SPI
import st7789py as st7789
def main():
# configure display
2021-12-23 18:54:40 +00:00
spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19))
tft = st7789.ST7789(
spi,
320,
240,
reset=Pin(4, Pin.OUT),
cs=Pin(13, Pin.OUT),
dc=Pin(12, Pin.OUT),
backlight=Pin(15, Pin.OUT),
rotation=0)
tft.fill(st7789.BLUE)
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()