11import time
22import board
3+ from random import randrange
34import rtc
45import terminalio
56from adafruit_matrixportal .matrixportal import MatrixPortal
2324)
2425
2526# --- Display Setup --- #
27+
28+ # Colors for guide name
29+ colors = [0xff0000 , 0xffa500 , 0xffff00 ,
30+ 0x008000 , 0x0000ff , 0x4b0082 ,
31+ 0xee82ee ]
32+
2633# Delay for scrolling the text
2734SCROLL_DELAY = 0.03
2835# id = 0, title
@@ -45,15 +52,27 @@ def get_guide_info(index):
4552 if index > DISPLAY_NUM_GUIDES :
4653 raise RuntimeError ("Provided index may not be larger than DISPLAY_NUM_GUIDES." )
4754 print ("Obtaining guide info for guide %d..." % index )
55+
4856 # Traverse JSON data for title
4957 guide_count = matrixportal .network .json_traverse (als_data .json (), ["guide_count" ])
58+ # Set guide count
59+ matrixportal .set_text (guide_count , 0 )
60+
5061 guides = matrixportal .network .json_traverse (als_data .json (), TITLE_DATA_LOCATION )
5162 guide_title = guides [index ]["guide" ]["title" ]
5263 print ("Guide Title" , guide_title )
53- return (guide_count , guide_title )
64+
65+ # Select color for title text
66+ color_index = randrange (0 , len (colors ))
5467
68+ # Set the title text color
69+ matrixportal .set_text_color (colors [color_index ], 1 )
5570
56- idx = 0
71+ # Set the title text
72+ matrixportal .set_text (guide_title , 1 )
73+
74+
75+ guide_idx = 0
5776prv_hour = 0
5877refresh_time = None
5978while True :
@@ -73,17 +92,12 @@ def get_guide_info(index):
7392 prv_hour = time .localtime ()[3 ]
7493
7594 # Cycle through guides retrieved
76- if idx < DISPLAY_NUM_GUIDES :
77- guide_count , guide_title = get_guide_info (idx )
78- # Set title text
79- matrixportal .set_text (guide_count , 0 )
80-
81- # Set author text
82- matrixportal .set_text (guide_title , 1 )
95+ if guide_idx < DISPLAY_NUM_GUIDES :
96+ get_guide_info (guide_idx )
8397
8498 # Scroll the scrollable text blocks
8599 matrixportal .scroll_text (SCROLL_DELAY )
86- idx += 1
100+ guide_idx += 1
87101 else :
88- idx = 0
102+ guide_idx = 0
89103 time .sleep (0.5 )
0 commit comments