-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclock.py
48 lines (38 loc) · 1.03 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
40
41
42
43
44
45
46
47
48
"""Clock"""
from datetime import datetime
from time import sleep
import psutil
from vfd import COLS, VFD
vfd = VFD(0, 0)
welcome = "Starting Clock"
def clock() -> str:
"""Get the time."""
now = datetime.now()
return now.strftime("%H:%M:%S")
def cpu_state() -> str:
"""Get CPU data."""
cpu_temp = psutil.sensors_temperatures()['cpu-thermal'][0].current
return f'{int(psutil.cpu_freq().current)} MHz {cpu_temp:.1f} C'
def main():
print(welcome)
vfd.home()
vfd.text(welcome.center(COLS))
sleep(3)
try:
while True:
vfd.home()
vfd.text(clock().center(COLS))
vfd.setCursor(0, 1)
vfd.text(cpu_state().center(COLS))
sleep(0.5)
except KeyboardInterrupt:
print("Stopping..")
vfd.clear()
vfd.text("User interrupted".center(COLS))
sleep(2)
vfd.clear()
print("Stopped")
finally:
vfd.clear()
if __name__ == "__main__":
main()