forked from malcolmholmes/pico-clock-green-python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.py
39 lines (32 loc) · 1.02 KB
/
clock.py
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
import time
from apps import App
from display import Display
from rtc import RTC
class Clock(App):
def __init__(self, scheduler):
App.__init__(self, "Clock", "clock")
self.display = Display(scheduler)
self.rtc = RTC()
self.enabled = True
scheduler.schedule("clock-second", 1000, self.secs_callback)
scheduler.schedule("clock-minute", 60000, self.mins_callback)
def enable(self):
self.enabled = True
self.update_time()
def disable(self):
self.enabled = False
def secs_callback(self, t):
if self.enabled:
t = time.time()
if t % 2 == 0:
self.display.show_char(":", pos=10)
else:
self.display.show_char(" :", pos=10)
def mins_callback(self, t):
if self.enabled:
self.update_time()
def update_time(self):
t = self.rtc.get_time()
now = "%02d:%02d" % (t[3], t[4])
self.display.show_day(t[6])
self.display.show_text(now)