-
Notifications
You must be signed in to change notification settings - Fork 0
/
clock.py
122 lines (102 loc) · 3.56 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
from sense_hat import SenseHat
import datetime
import time
sense = SenseHat()
sense.low_light = True
sense.rotation = 180
# unit: 60/29
u = 60.0/29
zero = [[0,0,1,1,0,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,0,1,1,0,0]]
one=[[0,0,0,1,0,0],[0,0,1,1,0,0],[0,0,0,1,0,0],[0,0,0,1,0,0],[0,0,0,1,0,0],[0,0,1,1,1,0]]
two=[[0,0,1,1,0,0],[0,1,0,0,1,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[0,0,1,0,0,0],[0,1,1,1,1,0]]
three=[[0,0,1,1,0,0],[0,1,0,0,1,0],[0,0,0,1,0,0],[0,0,0,0,1,0],[0,1,0,0,1,0],[0,0,1,1,0,0]]
four=[[0,0,0,0,1,0],[0,0,0,1,1,0],[0,0,1,0,1,0],[0,1,1,1,1,0],[0,0,0,0,1,0],[0,0,0,0,1,0]]
five=[[0,1,1,1,1,0],[0,1,0,0,0,0],[0,1,1,1,0,0],[0,0,0,0,1,0],[0,1,0,0,1,0],[0,0,1,1,0,0]]
six=[[0,0,1,1,0,0],[0,1,0,0,0,0],[0,1,1,1,0,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,0,1,1,0,0]]
seven=[[0,1,1,1,1,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[0,0,0,1,0,0],[0,0,1,0,0,0],[0,0,1,0,0,0]]
eight=[[0,0,1,1,0,0],[0,1,0,0,1,0],[0,0,1,1,0,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,0,1,1,0,0]]
nine=[[0,0,1,1,0,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,0,1,1,1,0],[0,0,0,0,1,0],[0,0,1,1,0,0]]
ten=[[0,1,0,0,1,0],[1,1,0,1,0,1],[0,1,0,1,0,1],[0,1,0,1,0,1],[0,1,0,1,0,1],[0,1,0,0,1,0]]
eleven=[[0,1,0,0,1,0],[1,1,0,1,1,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,1,0,0,1,0],[0,1,0,0,1,0]]
twelve=[[0,1,0,0,1,0],[1,1,0,1,0,1],[0,1,0,0,0,1],[0,1,0,0,1,0],[0,1,0,1,0,0],[0,1,0,1,1,1]]
nums = [zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve]
# hour background color
z = [0,0,0]
# hour number color
w = [255,255,255]
# minute background color
e = [0,0,0]
# minute dot color
x = [0,0,255]
def row_one(m):
result = [0,0,0,0,0,0,0,0]
if m > u*4 and m < u*25:
result = [0,0,0,0,1,1,1,1]
else:
if m < u:
result = [0,0,0,0,0,0,0,0]
elif m < u*2:
result = [0,0,0,0,1,0,0,0]
elif m < u*3:
result = [0,0,0,0,1,1,0,0]
elif m < u*4:
result = [0,0,0,0,1,1,1,0]
elif m < u*25:
result = [0,0,0,0,1,1,1,1]
elif m < u*26:
result = [1,0,0,0,1,1,1,1]
elif m < u*27:
result = [1,1,0,0,1,1,1,1]
elif m < u*28:
result = [1,1,1,0,1,1,1,1]
else:
result = [1,1,1,1,1,1,1,1]
return result
def row_eight(m):
result = [1,1,1,1,1,1,1,1]
if m < u*18:
if m < u*11:
result = [0,0,0,0,0,0,0,0]
elif m < u*12:
result = [0,0,0,0,0,0,0,1]
elif m < u*13:
result = [0,0,0,0,0,0,1,1]
elif m < u*14:
result = [0,0,0,0,0,1,1,1]
elif m < u*15:
result = [0,0,0,0,1,1,1,1]
elif m < u*16:
result = [0,0,0,1,1,1,1,1]
elif m < u*17:
result = [0,0,1,1,1,1,1,1]
else:
result = [0,1,1,1,1,1,1,1]
return result
def convert_to_color(arr, background, color):
return [background if j == 0 else color for j in arr]
def update_clock(hh, mm):
if hh > 12:
hh = hh - 12
img = []
# row 1
row1 = row_one(mm)
img.extend(convert_to_color(row1, e, x))
# row 2-7
for i in range(6):
if mm > (u*(24-i)):
img.append(x)
else:
img.append(e)
# hour number
img.extend(convert_to_color(nums[hh][i], z, w))
if mm > (u*(5+i)):
img.append(x)
else:
img.append(e)
#row 8
row8 = row_eight(mm)
img.extend(convert_to_color(row8, e, x))
sense.set_pixels(img)
def kloktonen():
now = datetime.datetime.now()
update_clock(now.hour, now.minute*1.0)