-
Notifications
You must be signed in to change notification settings - Fork 37
/
binary-clock.py
executable file
·65 lines (50 loc) · 1.25 KB
/
binary-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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from blinkt import set_pixel, clear, show
from time import localtime, sleep
MODE_HOUR = 0
MODE_MIN = 1
MODE_SEC = 2
time_to_stay_in_mode = 3
time_in_mode = 0
mode = 0
lh = 0
lm = 0
while True:
t = localtime()
h, m, s = t.tm_hour, t.tm_min, t.tm_sec
print(h, m, s, mode, time_in_mode)
if h != lh:
mode = MODE_HOUR
time_in_mode = 0
elif m != lm:
mode = MODE_MIN
time_in_mode = 0
lm = m
lh = h
clear()
if (s % 2) == 0:
set_pixel(1, 64, 64, 64)
if mode == MODE_HOUR:
set_pixel(0, 255, 0, 0)
for x in range(6):
bit = (h & (1 << x)) > 0
r, g, b = [128 * bit] * 3
set_pixel(7 - x, r, g, b)
if mode == MODE_MIN:
set_pixel(0, 0, 255, 0)
for x in range(6):
bit = (m & (1 << x)) > 0
r, g, b = [128 * bit] * 3
set_pixel(7 - x, r, g, b)
if mode == MODE_SEC:
set_pixel(0, 0, 0, 255)
for x in range(6):
bit = (s & (1 << x)) > 0
r, g, b = [128 * bit] * 3
set_pixel(7 - x, r, g, b)
show()
time_in_mode += 1
if time_in_mode == time_to_stay_in_mode:
mode += 1
mode %= 3
time_in_mode = 0
sleep(1)