forked from tdamdouni/Raspberry-Pi-DIY-Projects
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbinary_clock_uni.py
executable file
·36 lines (31 loc) · 942 Bytes
/
binary_clock_uni.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
#!/usr/bin/env python
import unicornhat as hat
import time, datetime
year_color = (0, 255, 0)
month_color = (0, 0, 255)
day_color = (255, 0, 0)
hour_color = (0, 255, 0)
minute_color = (0, 0, 255)
second_color = (255, 0, 0)
hundrefths_color = (127, 127, 0)
off = (0, 0, 0)
hat.clear()
hat.brightness(0.5)
def display_binary(value, row, color):
binary_str = "{0:8b}".format(value)
for x in range(0, 8):
if binary_str[x] == '1':
hat.set_pixel(x, row, color[0], color[1], color[2])
else:
hat.set_pixel(x, row, 0, 0, 0)
while True:
t = datetime.datetime.now()
display_binary(t.year % 100, 0, year_color)
display_binary(t.month, 1, month_color)
display_binary(t.day, 2, day_color)
display_binary(t.hour, 3, hour_color)
display_binary(t.minute, 4, minute_color)
display_binary(t.second, 5, second_color)
display_binary(t.microsecond / 10000, 6, hundrefths_color)
hat.show()
time.sleep(0.0001)