|
6 | 6 | from adafruit_bitmap_font import bitmap_font |
7 | 7 | from adafruit_display_text import label |
8 | 8 |
|
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.\"" |
10 | 12 |
|
11 | | -splash = displayio.Group() |
12 | | -board.DISPLAY.root_group = splash |
| 13 | +# set up display |
| 14 | +display = displayio.Group() |
| 15 | +board.DISPLAY.root_group = display |
13 | 16 |
|
| 17 | +# load font |
14 | 18 | font = bitmap_font.load_font("/fonts/icl16x16u.bdf") |
15 | 19 |
|
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) |
18 | 23 |
|
19 | | -wpm = 240 |
| 24 | +reader_label = label.Label(font, text="", color=0xf9e4bc, x=25, y=60) |
| 25 | +display.append(reader_label) |
20 | 26 |
|
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 = "" |
23 | 30 |
|
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 |
27 | 40 |
|
28 | 41 | 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: |
30 | 46 | pass |
31 | 47 |
|
| 48 | + # clear display |
| 49 | + clear_display() |
32 | 50 | time.sleep(1) |
33 | | - for word in words: |
34 | | - reader_area.text = word |
35 | 51 |
|
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 |
39 | 55 |
|
40 | | - time.sleep(60 / wpm) |
| 56 | + if word[-1] in {".", "?", "!", "\""}: |
| 57 | + time.sleep(sentence_pause) |
| 58 | + elif word[-1] == ",": |
| 59 | + time.sleep(comma_pause) |
41 | 60 |
|
| 61 | + time.sleep(60 / words_per_minute) |
42 | 62 | time.sleep(1) |
43 | | - reader_area.text = "" |
| 63 | + |
| 64 | + # clear display |
| 65 | + clear_display() |
| 66 | + time.sleep(3) |
0 commit comments