Commit fb30e2ee authored by Russ's avatar Russ

Fixes and tweaks to demo's

parent a9355821
"""
ttgo_hello.py
pyb_hello.py
Writes "Hello!" in random colors at random locations on a
on a ST7789 TFT display connected to a pyboard1.1.
video: https://youtu.be/OtcERmad5ps
https://youtu.be/OtcERmad5ps
"""
import random, time
from pyb import SPI, Pin
......
"""
pyb_scroll.py
Smoothly scroll all characters of a font up the screen. Fonts heights
must be even multiples of the screen height (i.e. 8 or 16 pixels high).
https://youtu.be/ro13rvaLKAc
"""
import utime
import random
from pyb import SPI, Pin
import st7789
# choose a font
# import vga1_8x8 as font
# import vga2_8x8 as font
# import vga1_8x16 as font
# import vga2_8x16 as font
# import vga1_16x16 as font
# import vga1_bold_16x16 as font
# import vga2_16x16 as font
import vga2_bold_16x16 as font
def cycle(p):
try:
len(p)
except TypeError:
cache = []
for i in p:
yield i
cache.append(i)
p = cache
while p:
yield from p
def main():
tft = st7789.ST7789(
SPI(1, SPI.MASTER, baudrate=30000000, polarity=1, phase=0),
240,
320,
reset=Pin('X3', Pin.OUT),
cs=Pin('X5', Pin.OUT),
dc=Pin('X4', Pin.OUT),
backlight=Pin('X2', Pin.OUT),
rotation=0)
colors = cycle([0xe000, 0xece0, 0xe7e0, 0x5e0, 0x00d3, 0x7030])
foreground = next(colors)
background = st7789.BLACK
tft.init()
tft.fill(background)
utime.sleep(1)
height = tft.height()
width = tft.width()
last_line = height - font.HEIGHT
tfa = 0
tfb = 0
tft.vscrdef(tfa, height, tfb)
scroll = 0
character = 0
while True:
# clear top line before scrolling off display
tft.fill_rect(0, scroll, width, 1, background)
# Write new line when we have scrolled the height of a character
if scroll % font.HEIGHT == 0:
line = (scroll + last_line) % height
# write character hex value as a string
tft.text(
font,
'x{:02x}'.format(character),
0,
line,
foreground,
background)
# write character using a integer (could be > 0x7f)
tft.text(
font,
character,
64,
line,
foreground,
background)
# write character+128 hex value as a string
tft.text(
font,
'x{:02x}'.format(character+128),
120,
line,
foreground,
background)
# write character+128 using a integer (could be > 0x7f)
tft.text(
font,
character+128,
184,
line,
foreground,
background)
# change color for next line
foreground = next(colors)
# next character with rollover at 256
character += 1
character %= 128
tft.vscsad(scroll+tfa)
scroll +=1
scroll %= height
utime.sleep(0.01)
main()
......@@ -14,7 +14,7 @@ import st7789 as st7789
import time
import utime
from fonts import vga2_8x16 as font
import vga2_8x16 as font
def main():
......
......@@ -11,23 +11,10 @@ import random
from machine import Pin, SPI
import st7789
# Choose fonts
import vga1_8x8 as font1
#import vga2_8x8 as font1
import vga1_8x16 as font2
#import vga2_8x16 as font2
# import vga1_16x16 as font3
import vga1_bold_16x16 as font3
# import vga2_16x16 as font3
#import vga2_bold_16x16 as font3
# import vga1_16x32 as font4
import vga1_bold_16x32 as font4
# import vga2_16x32 as font4
#import vga2_bold_16x32 as font4
def main():
tft = st7789.ST7789(
......
......@@ -4,7 +4,7 @@ ttgo_hello.py
Writes "Hello!" in random colors at random locations on a
LILYGO® TTGO T-Display.
https://www.youtube.com/watch?v=atBa0BYPAAc
https://youtu.be/z41Du4GDMSY
"""
import random
......@@ -13,21 +13,21 @@ import st7789
# Choose a font
# from fonts import vga1_8x8 as font
# from fonts import vga2_8x8 as font
# import vga1_8x8 as font
# import vga2_8x8 as font
# from fonts import vga1_8x16 as font
# from fonts import vga2_8x16 as font
# import vga1_8x16 as font
# 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
# import vga1_16x16 as font
# import vga1_bold_16x16 as font
# import vga2_16x16 as font
# import vga2_bold_16x16 as font
# from fonts import vga1_16x32 as font
# from fonts import vga1_bold_16x32 as font
# from fonts import vga2_16x32 as font
from fonts import vga2_bold_16x32 as font
# import vga1_16x32 as font
# import vga1_bold_16x32 as font
# import vga2_16x32 as font
import vga2_bold_16x32 as font
def main():
tft = st7789.ST7789(
......
"""
ttgo_fonts.py
ttgo_scroll.py
Smoothly scrolls all font characters up the screen on the LILYGO® TTGO
T-Display. Only works with fonts with heights that are even multiples of
the screen height, (i.e. 8 or 16 pixels high)
Smoothly scroll all characters of a font up the LILYGO® TTGO T-Display
screen. Fonts heights must be even multiples of the screen height
(i.e. 8 or 16 pixels high).
https://youtu.be/GQa-RzHLBak
"""
import utime
import random
......@@ -12,7 +13,6 @@ from machine import Pin, SPI
import st7789
# choose a font
# import vga1_8x8 as font
# import vga2_8x8 as font
# import vga1_8x16 as font
......@@ -20,10 +20,22 @@ import st7789
# import vga1_16x16 as font
# import vga1_bold_16x16 as font
# import vga2_16x16 as font
import vga2_bold_16x16 as font
def main():
def cycle(p):
try:
len(p)
except TypeError:
cache = []
for i in p:
yield i
cache.append(i)
p = cache
while p:
yield from p
def main():
tft = st7789.ST7789(
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
135,
......@@ -34,36 +46,62 @@ def main():
backlight=Pin(4, Pin.OUT),
rotation=0)
colors = cycle([0xe000, 0xece0, 0xe7e0, 0x5e0, 0x00d3, 0x7030])
foreground = next(colors)
background = st7789.BLACK
tft.init()
tft.fill(background)
utime.sleep(1)
height = tft.height()
width = tft.width()
last_line = height - font.HEIGHT
print(tft.width(), tft.height())
last_line = tft.height() - font.HEIGHT
tfa = 40
tfb = 40
tft.vscrdef(tfa, 240, tfb)
tfa = 40 # top free area
tfb = 40 # bottom free area
tft.vscrdef(tfa, height, tfb)
tft.fill(st7789.BLUE)
scroll = 0
character = 0
while True:
tft.fill_rect(0,scroll, tft.width(), 1, st7789.BLUE)
# clear top line before scrolling off display
tft.fill_rect(0, scroll, width, 1, background)
# Write new line when we have scrolled the height of a character
if scroll % font.HEIGHT == 0:
line = (scroll + last_line) % height
# write character hex value as a string
tft.text(
font,
'x{:02x}'.format(character),
16,
line,
foreground,
background)
# write character using a integer (could be > 0x7f)
tft.text(
font,
'\\x{:02x}= {:s} '.format(character, chr(character)),
0,
(scroll + last_line) % tft.height(),
st7789.WHITE,
st7789.BLUE)
character,
90,
line,
foreground,
background)
character = character +1 if character < 256 else 0
# change color for next line
foreground = next(colors)
tft.vscsad(scroll+tfa)
scroll +=1
# next character with rollover at 256
character += 1
character %= 256
if scroll == tft.height:
scroll = 0
# scroll the screen up 1 row
tft.vscsad(scroll+tfa)
scroll += 1
scroll %= height
utime.sleep(0.01)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment