1
+ import time
2
+ import board
3
+ import terminalio
4
+ import rtc
5
+ from adafruit_matrixportal .matrixportal import MatrixPortal
6
+
7
+ # --- Data Setup --- #
8
+ GUIDE_INDEX = 0
9
+ # Number of guides to fetch and display from the Adafruit Learning System
10
+ DISPLAY_NUM_GUIDES = 5
11
+ DATA_SOURCE = "https://learn.adafruit.com/api/guides/new.json?count=%d" % DISPLAY_NUM_GUIDES
12
+ TITLE_DATA_LOCATION = ["guides" , GUIDE_INDEX , "guide" , "title" ]
13
+ TAGLINE_DATA_LOCATION = ["guides" , GUIDE_INDEX , "guide" , "tagline" ]
14
+
15
+ # the current working directory (where this file is)
16
+ cwd = ("/" + __file__ ).rsplit ("/" , 1 )[0 ]
17
+
18
+ matrixportal = MatrixPortal (
19
+ url = DATA_SOURCE ,
20
+ json_path = TITLE_DATA_LOCATION ,
21
+ status_neopixel = board .NEOPIXEL ,
22
+ debug = True
23
+ )
24
+
25
+ print (matrixportal .graphics .display .height )
26
+ matrixportal .add_text (
27
+ text_font = terminalio .FONT ,
28
+ text_position = (2 , 4 ),
29
+ text_color = 0xFFFFFF ,
30
+ scrolling = True ,
31
+ )
32
+
33
+
34
+
35
+ refresh_time = None
36
+ while True :
37
+ # Query local time every hour and on first run
38
+ if (not refresh_time ) or (time .monotonic () - refresh_time ) > 3600 :
39
+ try :
40
+ print ("Getting time from internet!" )
41
+ matrixportal .get_local_time ()
42
+ refresh_time = time .monotonic ()
43
+ except RuntimeError as e :
44
+ print ("Some error occured, retrying! -" , e )
45
+ continue
46
+
47
+ the_time = time .localtime ()
48
+ print ("Time: " , the_time )
49
+
50
+ try :
51
+ print ("Index is " , GUIDE_INDEX )
52
+ # Update title location index
53
+ TITLE_DATA_LOCATION = ["guides" , GUIDE_INDEX , "guide" , "title" ]
54
+ matrixportal .json_path = TITLE_DATA_LOCATION
55
+ value = matrixportal .fetch ()
56
+ print ("Response is" , value )
57
+ except (ValueError , RuntimeError ) as e :
58
+ print ("Some error occured, retrying! -" , e )
59
+ matrixportal .scroll_text (0.01 )
60
+ if GUIDE_INDEX == DISPLAY_NUM_GUIDES - 1 : # reached the end of the guides
61
+ # reset the index
62
+ print ("Reached the end of the new guides, resetting!" )
63
+ GUIDE_INDEX = 0
64
+ GUIDE_INDEX += 1
65
+ time .sleep (0.5 )
0 commit comments