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

71 wiersze
1.6 KiB
Python
Czysty Zwykły widok Historia

2020-02-01 21:14:12 +00:00
"""
fonts.py
2020-02-01 21:14:12 +00:00
Smoothly scrolls all font characters up the screen on the display.
Only works with fonts with heights that are even multiples of
the screen height, (i.e. 8 or 16 pixels high)
2020-02-01 21:14:12 +00:00
"""
import utime
import random
2021-12-23 18:54:40 +00:00
from machine import Pin, SPI
2020-02-01 21:14:12 +00:00
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
2020-02-01 21:14:12 +00:00
def main():
2021-12-23 18:54:40 +00:00
spi = SPI(1, baudrate=31250000, sck=Pin(18), mosi=Pin(19))
2020-02-01 21:14:12 +00:00
tft = st7789.ST7789(
spi,
320,
2020-02-01 21:14:12 +00:00
240,
reset=Pin(4, Pin.OUT),
cs=Pin(13, Pin.OUT),
dc=Pin(12, Pin.OUT),
backlight=Pin(15, Pin.OUT),
2020-02-01 21:14:12 +00:00
rotation=0)
last_line = tft.height - font.HEIGHT
tfa = 0
tfb = 0
2020-02-01 21:14:12 +00:00
tft.vscrdef(tfa, 240, tfb)
tft.fill(st7789.BLUE)
scroll = 0
character = 0
2020-02-01 21:14:12 +00:00
while True:
tft.fill_rect(0, scroll, tft.width, 1, st7789.BLUE)
2020-02-01 21:14:12 +00:00
if scroll % font.HEIGHT == 0:
tft.text(
font,
'\\x{:02x}= {:s} '.format(character, chr(character)),
2020-02-01 21:14:12 +00:00
0,
(scroll + last_line) % tft.height,
st7789.WHITE,
st7789.BLUE)
character = character + 1 if character < 256 else 0
tft.vscsad(scroll + tfa)
scroll += 1
2020-02-01 21:14:12 +00:00
if scroll == tft.height:
scroll = 0
utime.sleep(0.01)
2020-02-01 21:14:12 +00:00
main()