@@ -41,51 +41,32 @@ Usage Example
41
41
import terminalio
42
42
from adafruit_matrixportal.matrixportal import MatrixPortal
43
43
44
- # You can display in 'GBP', 'EUR' or 'USD'
45
- CURRENCY = " USD"
46
- # Set up where we'll be fetching data from
47
- DATA_SOURCE = " https://api.coindesk.com/v1/bpi/currentprice.json"
48
- DATA_LOCATION = [" bpi" , CURRENCY , " rate_float" ]
49
-
50
-
51
- def text_transform (val ):
52
- if CURRENCY == " USD" :
53
- return " $%d " % val
54
- if CURRENCY == " EUR" :
55
- return " €%d " % val
56
- if CURRENCY == " GBP" :
57
- return " £%d " % val
58
- return " %d " % val
59
-
60
-
61
- # the current working directory (where this file is)
62
- cwd = (" /" + __file__ ).rsplit(" /" , 1 )[0 ]
63
-
64
- matrixportal = MatrixPortal(
65
- url = DATA_SOURCE ,
66
- json_path = DATA_LOCATION ,
67
- status_neopixel = board.NEOPIXEL ,
68
- debug = True ,
69
- )
44
+ # --- Display setup ---
45
+ matrixportal = MatrixPortal(status_neopixel = board.NEOPIXEL , debug = True )
70
46
47
+ # Create a new label with the color and text selected
71
48
matrixportal.add_text(
72
49
text_font = terminalio.FONT ,
73
- text_position = (16 , 16 ),
74
- text_color = 0x FFFFFF ,
75
- text_transform = text_transform,
50
+ text_position = (0 , (matrixportal.graphics.display.height // 2 ) - 1 ),
51
+ scrolling = True ,
76
52
)
77
- matrixportal.preload_font(b " $012345789" ) # preload numbers
78
- matrixportal.preload_font((0x 00A3 , 0x 20AC )) # preload gbp/euro symbol
53
+
54
+ SCROLL_DELAY = 0.03
55
+
56
+ contents = [
57
+ { ' text' : ' THIS IS RED' , ' color' : ' #cf2727' },
58
+ { ' text' : ' THIS IS BLUE' , ' color' : ' #0846e4' },
59
+ ]
79
60
80
61
while True :
81
- try :
82
- value = matrixportal.fetch()
83
- print (" Response is" , value)
84
- except (ValueError , RuntimeError ) as e:
85
- print (" Some error occured, retrying! -" , e)
62
+ for content in contents:
63
+ matrixportal.set_text(content[' text' ])
86
64
87
- time.sleep(3 * 60 ) # wait 3 minutes
65
+ # Set the text color
66
+ matrixportal.set_text_color(content[' color' ])
88
67
68
+ # Scroll it
69
+ matrixportal.scroll_text(SCROLL_DELAY )
89
70
90
71
Contributing
91
72
============
0 commit comments