2020-05-13 19:09:52 -04:00
|
|
|
"""
|
|
|
|
|
Writes "Hello!" in random colors at random locations.
|
|
|
|
|
"""
|
|
|
|
|
|
2020-05-09 13:03:13 -04:00
|
|
|
import random
|
|
|
|
|
from machine import Pin, SPI
|
|
|
|
|
import st7789
|
2020-05-13 19:09:52 -04:00
|
|
|
|
|
|
|
|
# Choose a font
|
2020-05-09 13:03:13 -04:00
|
|
|
#from fonts import vga1_8x8 as font
|
2020-05-13 19:09:52 -04:00
|
|
|
#from fonts import vga2_8x8 as font
|
|
|
|
|
#from fonts import vga1_8x16 as font
|
|
|
|
|
#from fonts import vga2_8x16 as font
|
|
|
|
|
#from fonts import vga1_16x16 as font
|
|
|
|
|
#from fonts import vga1_bold_16x16 as font
|
|
|
|
|
#from fonts import vga2_16x16 as font
|
|
|
|
|
from fonts import vga2_bold_16x16 as font
|
2020-05-09 13:03:13 -04:00
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
tft = st7789.ST7789(
|
2020-05-13 19:09:52 -04:00
|
|
|
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
|
|
|
|
|
135,
|
|
|
|
|
240,
|
|
|
|
|
reset=Pin(23, Pin.OUT),
|
|
|
|
|
cs=Pin(5, Pin.OUT),
|
|
|
|
|
dc=Pin(16, Pin.OUT),
|
|
|
|
|
backlight=Pin(4, Pin.OUT),
|
|
|
|
|
rotation=3
|
2020-05-09 13:03:13 -04:00
|
|
|
)
|
|
|
|
|
tft.init()
|
|
|
|
|
|
|
|
|
|
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(250):
|
|
|
|
|
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()
|