Skip to content

Commit 434b582

Browse files
committed
added typewriter effect to text display
1 parent 5ad0915 commit 434b582

File tree

1 file changed

+20
-13
lines changed
  • adafruit-esp32-s3-tft-feather/circuitpython/reader

1 file changed

+20
-13
lines changed

adafruit-esp32-s3-tft-feather/circuitpython/reader/code.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,20 @@
2323
#message = "\"You think your pain and your heartbreak are un- precedented in the history of the world, but then you read. It was books that taught me that the things that tormented me most were the very things that connected me with all the people who were alive, who had ever been alive.\""
2424
#author = "J. Baldwin"
2525

26-
prompt = ". . ."
26+
splash = "popcorn"
2727

2828
# set up display
2929
display = displayio.Group()
3030
board.DISPLAY.root_group = display
3131

3232
# load fonts
33-
splash_font = bitmap_font.load_font("/fonts/Comforta-Regular-16.bdf")
33+
splash_font = bitmap_font.load_font("/fonts/Comforta-Regular-20.bdf")
3434
reader_font = bitmap_font.load_font("/fonts/SourceCodePro-Regular-18.bdf")
3535
author_font = bitmap_font.load_font("/fonts/Comforta-Regular-20.bdf")
3636

3737
# configure labels
38-
splash_label = label.Label(splash_font, text="", color=0x202020, x=24, y=60)
38+
#splash_label = label.Label(splash_font, text="", color=0x202020, x=24, y=60)
39+
splash_label = label.Label(splash_font, text="", color=0xffffff, x=24, y=60)
3940
reader_label = label.Label(reader_font, text="", color=0xf9e4bc, x=24, y=58)
4041
dummy_label = label.Label(reader_font, text="", color=0x000000, x=24, y=58)
4142
author_label = label.Label(author_font, text="", color=0xef9d6e, x=24, y=58)
@@ -44,24 +45,30 @@
4445
display.append(reader_label)
4546
display.append(author_label)
4647

48+
# configure boot button
49+
boot_button = digitalio.DigitalInOut(board.BOOT0)
50+
boot_button.direction = digitalio.Direction.INPUT
51+
boot_button.pull = digitalio.Pull.UP
52+
4753
def clear_display(delay=0):
4854
splash_label.text = ""
4955
reader_label.text = ""
5056
author_label.text = ""
5157
time.sleep(delay)
5258

53-
# configure boot button
54-
boot_button = digitalio.DigitalInOut(board.BOOT0)
55-
boot_button.direction = digitalio.Direction.INPUT
56-
boot_button.pull = digitalio.Pull.UP
59+
def display_typed_text(label, text):
60+
for i in range(len(text) + 1):
61+
label.text = text[:i] + "|"
62+
time.sleep(0.05)
63+
label.text = text
5764

5865
# cache word bitmaps for speed of rendering
5966
for word in message.split():
6067
dummy_label.text = word.lower()
6168
clear_display()
6269

6370
while True:
64-
splash_label.text = prompt
71+
display_typed_text(splash_label, splash)
6572

6673
# wait for button press
6774
while boot_button.value:
@@ -80,14 +87,14 @@ def clear_display(delay=0):
8087
time.sleep(comma_pause)
8188

8289
time.sleep(word_pause)
83-
time.sleep(1)
90+
time.sleep(0.8)
8491

8592
# clear display
8693
clear_display(2)
8794

88-
# display author
89-
author_label.text = author
90-
time.sleep(3)
95+
# display author with typewriter effect
96+
display_typed_text(author_label, author)
97+
time.sleep(2.5)
9198

9299
# clear display
93-
clear_display()
100+
clear_display(1)

0 commit comments

Comments
 (0)