11# SPDX-FileCopyrightText: 2023 Melissa-LeBlanc-Williams for Adafruit Industries
2- # SPDX-FileCopyrightText: 2023 Erin St. Blaine for Adafruit Industries
32# SPDX-FileCopyrightText: 2020 John Park for Adafruit Industries
43#
54# SPDX-License-Identifier: MIT
65
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
1010
11- from collections import deque
1211import time
13- import random
1412import board
13+ import random
14+ from collections import deque
1515from adafruit_matrixportal .matrix import Matrix
1616from adafruit_matrixportal .network import Network
1717from messageboard import MessageBoard
2525DEFAULT_FONT = "arial_sm"
2626MESSAGES_FEED = "text"
2727COLORS_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
3030RANDOMIZE_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
3333
3434# --- Display setup ---
3535matrix = Matrix (width = WIDTH , height = HEIGHT , bit_depth = 5 )
4848message_queue = deque ((), 10000 ) # Use a double-ended queue for messages
4949colors = []
5050
51-
5251def update_data ():
5352 print ("Updating data from Adafruit IO" )
5453 # Only show connecting message if not connected
@@ -70,15 +69,15 @@ def update_data():
7069 try :
7170 messages_data = network .get_io_data (MESSAGES_FEED )
7271 message_ids = []
73- sms_messages = [] # Temporary place for messages
72+ messages = [] # Temporary place for messages
7473 for json_data in messages_data :
7574 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" ]))
7776
7877 # 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 )
8281
8382 # Remove any messages that have been grabbed except the latest one if setting enabled
8483 start_index = 1 if KEEP_LATEST_MESSAGE else 0
@@ -92,7 +91,6 @@ def update_data():
9291
9392 messageboard .animate (system_message , "Static" , "hide" )
9493
95-
9694def get_new_rand_item (current_index , item_list ):
9795 if not item_list :
9896 return None
@@ -144,9 +142,8 @@ def get_new_rand_item(current_index, item_list):
144142 message .add_text (message_text , color = message_color )
145143
146144 # 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 )
150147
151148 if time .monotonic () > last_update + UPDATE_DELAY :
152149 update_data ()
0 commit comments