1
1
# SPDX-FileCopyrightText: 2023 Melissa-LeBlanc-Williams for Adafruit Industries
2
- # SPDX-FileCopyrightText: 2023 Erin St. Blaine for Adafruit Industries
3
2
# SPDX-FileCopyrightText: 2020 John Park for Adafruit Industries
4
3
#
5
4
# SPDX-License-Identifier: MIT
6
5
7
- # SMS Message board matrix display
8
- # uses AdafruitIO to serve up a message text feed and color feed
9
- # messages are displayed in order, updates periodically to look for new messages
6
+ # Quote board matrix display
7
+ # uses AdafruitIO to serve up a quote text feed and color feed
8
+ # random messages are displayed, updates periodically to look for new messages
9
+ # avoids repeating the same quote twice in a row
10
10
11
- from collections import deque
12
11
import time
13
- import random
14
12
import board
13
+ import random
14
+ from collections import deque
15
15
from adafruit_matrixportal .matrix import Matrix
16
16
from adafruit_matrixportal .network import Network
17
17
from messageboard import MessageBoard
25
25
DEFAULT_FONT = "arial_sm"
26
26
MESSAGES_FEED = "text"
27
27
COLORS_FEED = "color"
28
- UPDATE_DELAY = 50 # Seconds between updates
29
- SCROLL_DURATION = 6 # Seconds to scroll entire message
28
+ UPDATE_DELAY = 50 # Seconds between updates
29
+ SCROLL_DURATION = 5 # Seconds to scroll entire message
30
30
RANDOMIZE_FONTS = True # Randomize fonts, make "False" to just use the default font
31
- RANDOMIZE_COLORS = True # Randomise colors, make "False" to just use the default color
32
- KEEP_LATEST_MESSAGE = True # Keep the last message in the Message Feed
31
+ RANDOMIZE_COLORS = True # Randomise colors, make "False" to just use the default color
32
+ KEEP_LATEST_MESSAGE = True # Keep the last message in the Message Feed
33
33
34
34
# --- Display setup ---
35
35
matrix = Matrix (width = WIDTH , height = HEIGHT , bit_depth = 5 )
48
48
message_queue = deque ((), 10000 ) # Use a double-ended queue for messages
49
49
colors = []
50
50
51
-
52
51
def update_data ():
53
52
print ("Updating data from Adafruit IO" )
54
53
# Only show connecting message if not connected
@@ -70,15 +69,15 @@ def update_data():
70
69
try :
71
70
messages_data = network .get_io_data (MESSAGES_FEED )
72
71
message_ids = []
73
- sms_messages = [] # Temporary place for messages
72
+ messages = [] # Temporary place for messages
74
73
for json_data in messages_data :
75
74
message_ids .append (network .json_traverse (json_data , ["id" ]))
76
- sms_messages .append (network .json_traverse (json_data , ["value" ]))
75
+ messages .append (network .json_traverse (json_data , ["value" ]))
77
76
78
77
# Results are returned in reverse order, so we reverse that and add to end of queue
79
- sms_messages .reverse ()
80
- for sms_message in sms_messages :
81
- message_queue .append (sms_message )
78
+ messages .reverse ()
79
+ for message in messages :
80
+ message_queue .append (message )
82
81
83
82
# Remove any messages that have been grabbed except the latest one if setting enabled
84
83
start_index = 1 if KEEP_LATEST_MESSAGE else 0
@@ -92,7 +91,6 @@ def update_data():
92
91
93
92
messageboard .animate (system_message , "Static" , "hide" )
94
93
95
-
96
94
def get_new_rand_item (current_index , item_list ):
97
95
if not item_list :
98
96
return None
@@ -144,9 +142,8 @@ def get_new_rand_item(current_index, item_list):
144
142
message .add_text (message_text , color = message_color )
145
143
146
144
# Scroll the message
147
- duration = SCROLL_DURATION / 2
148
- messageboard .animate (message , "Scroll" , "in_from_right" , duration = duration )
149
- messageboard .animate (message , "Scroll" , "out_to_left" , duration = duration )
145
+ duration = SCROLL_DURATION
146
+ messageboard .animate (message , "Scroll" , "right_to_left" , duration = SCROLL_DURATION )
150
147
151
148
if time .monotonic () > last_update + UPDATE_DELAY :
152
149
update_data ()
0 commit comments