Skip to content

Commit 68fb289

Browse files
author
brentru
committed
change guide title's color on each scroll
1 parent 9c7b6e6 commit 68fb289

File tree

1 file changed

+25
-11
lines changed

1 file changed

+25
-11
lines changed

Matrix_Portal_Learn_Stats/code.py

+25-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import time
22
import board
3+
from random import randrange
34
import rtc
45
import terminalio
56
from adafruit_matrixportal.matrixportal import MatrixPortal
@@ -23,6 +24,12 @@
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
2734
SCROLL_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
5776
prv_hour = 0
5877
refresh_time = None
5978
while 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

Comments
 (0)