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 Writes "Hello!" in random colors at random locations on a
on a ST7789 TFT display connected to a pyboard1.1. on a ST7789 TFT display connected to a pyboard1.1.
video: https://youtu.be/OtcERmad5ps https://youtu.be/OtcERmad5ps
""" """
import random, time import random, time
from pyb import SPI, Pin 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 ...@@ -14,7 +14,7 @@ import st7789 as st7789
import time import time
import utime import utime
from fonts import vga2_8x16 as font import vga2_8x16 as font
def main(): def main():
......
...@@ -11,23 +11,10 @@ import random ...@@ -11,23 +11,10 @@ import random
from machine import Pin, SPI from machine import Pin, SPI
import st7789 import st7789
# Choose fonts
import vga1_8x8 as font1 import vga1_8x8 as font1
#import vga2_8x8 as font1
import vga1_8x16 as font2 import vga1_8x16 as font2
#import vga2_8x16 as font2
# import vga1_16x16 as font3
import vga1_bold_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 vga1_bold_16x32 as font4
# import vga2_16x32 as font4
#import vga2_bold_16x32 as font4
def main(): def main():
tft = st7789.ST7789( tft = st7789.ST7789(
......
...@@ -4,7 +4,7 @@ ttgo_hello.py ...@@ -4,7 +4,7 @@ ttgo_hello.py
Writes "Hello!" in random colors at random locations on a Writes "Hello!" in random colors at random locations on a
LILYGO® TTGO T-Display. LILYGO® TTGO T-Display.
https://www.youtube.com/watch?v=atBa0BYPAAc https://youtu.be/z41Du4GDMSY
""" """
import random import random
...@@ -13,21 +13,21 @@ import st7789 ...@@ -13,21 +13,21 @@ import st7789
# Choose a font # Choose a font
# from fonts import vga1_8x8 as font # import vga1_8x8 as font
# from fonts import vga2_8x8 as font # import vga2_8x8 as font
# from fonts import vga1_8x16 as font # import vga1_8x16 as font
# from fonts import vga2_8x16 as font # import vga2_8x16 as font
# from fonts import vga1_16x16 as font # import vga1_16x16 as font
# from fonts import vga1_bold_16x16 as font # import vga1_bold_16x16 as font
# from fonts import vga2_16x16 as font # import vga2_16x16 as font
# from fonts import vga2_bold_16x16 as font # import vga2_bold_16x16 as font
# from fonts import vga1_16x32 as font # import vga1_16x32 as font
# from fonts import vga1_bold_16x32 as font # import vga1_bold_16x32 as font
# from fonts import vga2_16x32 as font # import vga2_16x32 as font
from fonts import vga2_bold_16x32 as font import vga2_bold_16x32 as font
def main(): def main():
tft = st7789.ST7789( tft = st7789.ST7789(
......
""" """
ttgo_fonts.py ttgo_scroll.py
Smoothly scrolls all font characters up the screen on the LILYGO® TTGO Smoothly scroll all characters of a font up the LILYGO® TTGO T-Display
T-Display. Only works with fonts with heights that are even multiples of screen. Fonts heights must be even multiples of the screen height
the screen height, (i.e. 8 or 16 pixels high) (i.e. 8 or 16 pixels high).
https://youtu.be/GQa-RzHLBak
""" """
import utime import utime
import random import random
...@@ -12,7 +13,6 @@ from machine import Pin, SPI ...@@ -12,7 +13,6 @@ from machine import Pin, SPI
import st7789 import st7789
# choose a font # choose a font
# import vga1_8x8 as font # import vga1_8x8 as font
# import vga2_8x8 as font # import vga2_8x8 as font
# import vga1_8x16 as font # import vga1_8x16 as font
...@@ -20,10 +20,22 @@ import st7789 ...@@ -20,10 +20,22 @@ import st7789
# import vga1_16x16 as font # import vga1_16x16 as font
# import vga1_bold_16x16 as font # import vga1_bold_16x16 as font
# import vga2_16x16 as font # import vga2_16x16 as font
import vga2_bold_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( tft = st7789.ST7789(
SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)), SPI(2, baudrate=30000000, polarity=1, phase=1, sck=Pin(18), mosi=Pin(19)),
135, 135,
...@@ -34,36 +46,62 @@ def main(): ...@@ -34,36 +46,62 @@ def main():
backlight=Pin(4, Pin.OUT), backlight=Pin(4, Pin.OUT),
rotation=0) rotation=0)
colors = cycle([0xe000, 0xece0, 0xe7e0, 0x5e0, 0x00d3, 0x7030])
foreground = next(colors)
background = st7789.BLACK
tft.init() tft.init()
tft.fill(background)
utime.sleep(1)
height = tft.height()
width = tft.width()
last_line = height - font.HEIGHT
print(tft.width(), tft.height()) tfa = 40 # top free area
last_line = tft.height() - font.HEIGHT tfb = 40 # bottom free area
tfa = 40 tft.vscrdef(tfa, height, tfb)
tfb = 40
tft.vscrdef(tfa, 240, tfb)
tft.fill(st7789.BLUE)
scroll = 0 scroll = 0
character = 0 character = 0
while True: 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: 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( tft.text(
font, font,
'\\x{:02x}= {:s} '.format(character, chr(character)), character,
0, 90,
(scroll + last_line) % tft.height(), line,
st7789.WHITE, foreground,
st7789.BLUE) background)
character = character +1 if character < 256 else 0 # change color for next line
foreground = next(colors)
tft.vscsad(scroll+tfa) # next character with rollover at 256
scroll +=1 character += 1
character %= 256
if scroll == tft.height: # scroll the screen up 1 row
scroll = 0 tft.vscsad(scroll+tfa)
scroll += 1
scroll %= height
utime.sleep(0.01) 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