1
1
import time
2
2
import board
3
+ from random import randrange
3
4
import rtc
4
5
import terminalio
5
6
from adafruit_matrixportal .matrixportal import MatrixPortal
23
24
)
24
25
25
26
# --- Display Setup --- #
27
+
28
+ # Colors for guide name
29
+ colors = [0xff0000 , 0xffa500 , 0xffff00 ,
30
+ 0x008000 , 0x0000ff , 0x4b0082 ,
31
+ 0xee82ee ]
32
+
26
33
# Delay for scrolling the text
27
34
SCROLL_DELAY = 0.03
28
35
# id = 0, title
@@ -45,15 +52,27 @@ def get_guide_info(index):
45
52
if index > DISPLAY_NUM_GUIDES :
46
53
raise RuntimeError ("Provided index may not be larger than DISPLAY_NUM_GUIDES." )
47
54
print ("Obtaining guide info for guide %d..." % index )
55
+
48
56
# Traverse JSON data for title
49
57
guide_count = matrixportal .network .json_traverse (als_data .json (), ["guide_count" ])
58
+ # Set guide count
59
+ matrixportal .set_text (guide_count , 0 )
60
+
50
61
guides = matrixportal .network .json_traverse (als_data .json (), TITLE_DATA_LOCATION )
51
62
guide_title = guides [index ]["guide" ]["title" ]
52
63
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 ))
54
67
68
+ # Set the title text color
69
+ matrixportal .set_text_color (colors [color_index ], 1 )
55
70
56
- idx = 0
71
+ # Set the title text
72
+ matrixportal .set_text (guide_title , 1 )
73
+
74
+
75
+ guide_idx = 0
57
76
prv_hour = 0
58
77
refresh_time = None
59
78
while True :
@@ -73,17 +92,12 @@ def get_guide_info(index):
73
92
prv_hour = time .localtime ()[3 ]
74
93
75
94
# 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 )
83
97
84
98
# Scroll the scrollable text blocks
85
99
matrixportal .scroll_text (SCROLL_DELAY )
86
- idx += 1
100
+ guide_idx += 1
87
101
else :
88
- idx = 0
102
+ guide_idx = 0
89
103
time .sleep (0.5 )
0 commit comments