-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScrollingClock.py
More file actions
executable file
·66 lines (57 loc) · 2.06 KB
/
ScrollingClock.py
File metadata and controls
executable file
·66 lines (57 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import time
import random
import board
import terminalio
from adafruit_matrixportal.matrixportal import MatrixPortal
colors = []
# colors.append(0x000000) # black background
colors.append(0xFF0000) # red
colors.append(0xCC4000) # amber
colors.append(0x85FF00) # greenish
SCROLL_SPEED = 0.025 # lower is faster, delay between refreshes
class myclock():
def __init__(self, portal):
self.last_color = 1
# --- Display setup ---
self.matrixportal = portal
def my_time(self):
colon = ':'
time_data = time.localtime()
is_dst = time_data[8]
year = time_data[0]
month = time_data[1]
day = time_data[2]
hour = time_data[3]
minute = time_data[4]
second = time_data[5]
hourtext = '{}{}{:02d}{}{:02d} - {:02d}{}{:02d}{}{:02d} '.format(
year, colon, month, colon, day, hour, colon, minute, colon, second)
return hourtext
def displayClock(self):
timeStr = self.my_time()
# Set the text
self.matrixportal.set_text(timeStr)
# Set the text color
color_index = 0
# Choose a random color from colors
if len(colors) > 1 and self.last_color is not None:
while color_index == self.last_color:
color_index = random.randrange(0, len(colors))
else:
color_index = random.randrange(0, len(colors))
self.last_color = color_index
self.matrixportal.set_text_color(colors[color_index])
# Scroll it
self.matrixportal.scroll_text(SCROLL_SPEED)
if __name__ == '__main__':
matrixportal = MatrixPortal(status_neopixel=board.NEOPIXEL, debug=True)
matrixportal.get_local_time()
# Create a new label with the color and text selected
matrixportal.add_text(
text_font=terminalio.FONT,
text_position=(0, (matrixportal.graphics.display.height // 2) - 1),
scrolling=True,)
# Set the time to local time
my_time = myclock(matrixportal)
while True:
my_time.displayClock()