Skip to content

Commit 526361d

Browse files
committed
added version. completed code review enhancements
1 parent 2d3f3f3 commit 526361d

File tree

1 file changed

+37
-20
lines changed
  • adafruit-esp32-s3-tft-feather/circuitpython/popcorn_reader

1 file changed

+37
-20
lines changed

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

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,27 @@
66
from adafruit_bitmap_font import bitmap_font
77
from adafruit_display_text import label
88

9+
splash = "popcorn"
10+
version = "0.0.2"
11+
912
# reading parameters
1013
words_per_minute = 280
1114
sentence_pause = 1.2
1215
comma_pause = 0.4
1316

1417
word_pause = 60 / words_per_minute
1518

19+
# font colors
20+
splash_font_color = 0xf9e4bc
21+
reader_font_color = 0xfaf6ea
22+
author_font_color = 0xef9d6e
23+
version_font_color = 0x202020
24+
25+
# font paths
26+
splash_font_path = "/fonts/Comforta-Regular-20.bdf"
27+
reader_font_path = "/fonts/SourceCodePro-Regular-18.bdf"
28+
author_font_path = "/fonts/Comforta-Regular-20.bdf"
29+
1630
# message to display
1731
message = "\"The capacity to be alone is the capacity to love. It may look paradoxical to you, but it's not. It is an existential truth: only those people who are capable of being alone are capable of love, of sharing, of going into the deepest core of another person without possessing the other, without becoming dependent on the other, without reducing the other to a thing, and without becoming addicted to the other. They allow the other absolute freedom, because they know that if the other leaves, they will be as happy as they are now. Their happiness cannot be taken by the other, because it is not given by the other.\""
1832
author = "Osho"
@@ -23,21 +37,22 @@
2337
#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.\""
2438
#author = "J. Baldwin"
2539

26-
splash = "popcorn"
40+
words = message.split()
2741

2842
# set up display
2943
display = displayio.Group()
3044
board.DISPLAY.root_group = display
3145

3246
# load fonts
33-
splash_font = bitmap_font.load_font("/fonts/Comforta-Regular-20.bdf")
34-
reader_font = bitmap_font.load_font("/fonts/SourceCodePro-Regular-18.bdf")
35-
author_font = bitmap_font.load_font("/fonts/Comforta-Regular-20.bdf")
47+
splash_font = bitmap_font.load_font(splash_font_path)
48+
reader_font = bitmap_font.load_font(reader_font_path)
49+
author_font = bitmap_font.load_font(author_font_path)
3650

3751
# configure labels
38-
splash_label = label.Label(splash_font, text="", color=0xffffff, x=24, y=60)
39-
reader_label = label.Label(reader_font, text="", color=0xf9e4bc, x=24, y=58)
40-
author_label = label.Label(author_font, text="", color=0xef9d6e, x=24, y=58)
52+
splash_label = label.Label(splash_font, text="", color=splash_font_color, x=24, y=60)
53+
reader_label = label.Label(reader_font, text="", color=reader_font_color, x=24, y=58)
54+
author_label = label.Label(author_font, text="", color=author_font_color, x=24, y=58)
55+
version_label = label.Label(terminalio.FONT, text=version, color=version_font_color, x=200, y=120)
4156

4257
cache_splash_label = label.Label(splash_font, text="", color=0x000000, x=24, y=60)
4358
cache_reader_label = label.Label(reader_font, text="", color=0x000000, x=24, y=58)
@@ -46,6 +61,7 @@
4661
display.append(splash_label)
4762
display.append(reader_label)
4863
display.append(author_label)
64+
display.append(version_label)
4965

5066
# configure boot button
5167
boot_button = digitalio.DigitalInOut(board.BOOT0)
@@ -58,46 +74,47 @@ def clear_display(delay=0):
5874
author_label.text = ""
5975
time.sleep(delay)
6076

61-
def display_typed_text(label, text, delay=0.05):
77+
# display with typewriter effect
78+
def display_typed_text(label, text, delay=0.05, cache_label=None):
79+
if cache_label is not None:
80+
for i in range(len(text) + 1):
81+
cache_label.text = text[:i] + "|"
82+
6283
for i in range(len(text) + 1):
6384
label.text = text[:i] + "|"
6485
time.sleep(delay)
6586
label.text = text
6687

6788
while True:
68-
display_typed_text(cache_splash_label, splash, 0)
69-
display_typed_text(splash_label, splash)
89+
# display splash
90+
display_typed_text(splash_label, splash, cache_label=cache_splash_label)
7091

7192
# wait for button press
7293
while boot_button.value:
7394
pass
7495

75-
# clear display
7696
clear_display()
7797

7898
# display words
79-
for word in message.split(): # cache word bitmaps for speed of rendering
99+
for word in words: # cache bitmaps
80100
cache_reader_label.text = word.lower()
81101
clear_display()
82102

83-
for word in message.split():
103+
for word in words:
84104
reader_label.text = word.lower()
85105

86-
if word[-1] in {".", "?", "!", "\"", ";", "—", "–", "-"}:
106+
if word[-1] in {".", "?", "!", "\"", ";", "—", "–"}:
87107
time.sleep(sentence_pause)
88108
elif word[-1] in {",", ":"}:
89109
time.sleep(comma_pause)
90110

91111
time.sleep(word_pause)
92112
time.sleep(0.8)
93113

94-
# clear display
95114
clear_display(1)
96115

97-
# display author with typewriter effect
98-
display_typed_text(cache_author_label, author, 0)
99-
display_typed_text(author_label, author)
100-
time.sleep(4)
116+
# display author
117+
display_typed_text(author_label, author, cache_label=cache_author_label)
118+
time.sleep(3.5)
101119

102-
# clear display
103120
clear_display(1)

0 commit comments

Comments
 (0)