Skip to content

Commit d517a8f

Browse files
committed
updated based on code review and updated message
1 parent 1a4d387 commit d517a8f

File tree

1 file changed

+42
-19
lines changed
  • adafruit-esp32-s3-tft-feather/circuitpython/reader

1 file changed

+42
-19
lines changed

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

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,61 @@
66
from adafruit_bitmap_font import bitmap_font
77
from adafruit_display_text import label
88

9-
boot_button = board.BOOT0
9+
# message to display
10+
message = "Physical concepts are free creations of the human mind, and are not, however it may seem, uniquely determined by the external world. In our endeavor to understand reality we are somewhat like a man trying to understand the mechanism of a closed watch. He sees the face and the moving hands, even hears its ticking, but he has no way of opening the case. If he is ingenious, he may form some picture of a mechanism which could be responsible for all the things he observes, but he may never be quite sure his picture is the only one which could explain his observations. He will never be able to compare his picture with the real mechanism and he cannot even imagine the possibility or the meaning of such a comparison."
11+
#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.\""
1012

11-
splash = displayio.Group()
12-
board.DISPLAY.root_group = splash
13+
# set up display
14+
display = displayio.Group()
15+
board.DISPLAY.root_group = display
1316

17+
# load font
1418
font = bitmap_font.load_font("/fonts/icl16x16u.bdf")
1519

16-
reader_area = label.Label(font, text="", color=0xf9e4bc, x=25, y=60)
17-
splash.append(reader_area)
20+
# configure labels
21+
message_label = label.Label(terminalio.FONT, text="", color=0x181818, x=25, y=60)
22+
display.append(message_label)
1823

19-
wpm = 240
24+
reader_label = label.Label(font, text="", color=0xf9e4bc, x=25, y=60)
25+
display.append(reader_label)
2026

21-
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.\""
22-
words = message.split()
27+
def clear_display():
28+
message_label.text = ""
29+
reader_label.text = ""
2330

24-
button = digitalio.DigitalInOut(boot_button)
25-
button.direction = digitalio.Direction.INPUT
26-
button.pull = digitalio.Pull.UP
31+
# reading parameters
32+
words_per_minute = 240
33+
sentence_pause = 0.5
34+
comma_pause = 0.2
35+
36+
# configure boot button
37+
boot_button = digitalio.DigitalInOut(board.BOOT0)
38+
boot_button.direction = digitalio.Direction.INPUT
39+
boot_button.pull = digitalio.Pull.UP
2740

2841
while True:
29-
while button.value:
42+
message_label.text = "( press boot button to begin )"
43+
44+
# wait for button press
45+
while boot_button.value:
3046
pass
3147

48+
# clear display
49+
clear_display()
3250
time.sleep(1)
33-
for word in words:
34-
reader_area.text = word
3551

36-
last_char = word[-1]
37-
if (last_char == ".") or (last_char == "?") or (last_char == "!"):
38-
time.sleep(0.5)
52+
# display words
53+
for word in message.split():
54+
reader_label.text = word
3955

40-
time.sleep(60 / wpm)
56+
if word[-1] in {".", "?", "!", "\""}:
57+
time.sleep(sentence_pause)
58+
elif word[-1] == ",":
59+
time.sleep(comma_pause)
4160

61+
time.sleep(60 / words_per_minute)
4262
time.sleep(1)
43-
reader_area.text = ""
63+
64+
# clear display
65+
clear_display()
66+
time.sleep(3)

0 commit comments

Comments
 (0)