This repository was archived by the owner on Oct 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
89 lines (67 loc) · 2.19 KB
/
Copy pathmain.py
File metadata and controls
89 lines (67 loc) · 2.19 KB
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
""""
Binary clock with micropython
8x8 dot matrix: clk->GPIO14(D5), din->GPIO13(D7), cs->GPIO15(D8)
ds1307 RTC: scl->GPIO5(D1), sda->GPIO4(D2)
"""
from machine import I2C, Pin, SPI
import max7219 as mx
import ds1307, bcd
from time import sleep
#from time import localtime- for use with internal rtc
i2c = I2C(Pin(5), Pin(4))
spi = SPI(1, baudrate=10000000, polarity=0, phase=0)
display = mx.Matrix8x8(spi, Pin(15), 1)
ds = ds1307.DS1307(i2c)
def get_time():
return ds.datetime() #localtime() for internal rtc
class TimeToBCD:
def __init__(self, time):
self.datetime = time #(yy, mm, dd, wday, hh, mm, ss, mill_s)
self.month = self.datetime[1]
self.day = self.datetime[2]
self.hour = self.datetime[4]
self.min = self.datetime[5]
#convert to BCD
self.month = self.to_BCD(self.month)
self.day = self.to_BCD(self.day)
self.hour= self.to_BCD(self.hour)
self.min = self.to_BCD(self.min)
def to_BCD(self, intValue):
bcd_repr = bcd.BCDConversion(intValue)
return bcd_repr
def get_time(self):
return (self.hour, self.min)
def get_date(self):
return (self.month, self.day)
def display_time():
#led matrix time array
time_matrix = [('7', [7, 6, 5, 4]),
('6', [7, 6, 5, 4]),
('5', [7, 6, 5, 4]),
('4', [7, 6, 5, 4])]
#led matrix date array
date_matrix = {'3':[3, 2, 1, 0],
'2':[3, 2, 1, 0],
'1':[3, 2, 1, 0],
'0':[3, 2, 1, 0]}
bcd_time = TimeToBCD(get_time())
time = bcd_time.get_time()
date = bcd_time.get_date()
#[("xxxx", "xxxx"), ("xxxx", "xxxx")] => [("xxxx"), ("xxxx"), ("xxxx"), ("xxxx")]
time = [y for x in time for y in x]
date = [y for x in date for y in x]
for i in range(4):
for j in range(4):
pixel = (int(date_matrix[i][0]), date_matrix[i][1][j], int(date[i][j]))
x, y, brightness = pixel
display.pixel(x, y, brightness)
display.show()
for i in range(4):
for j in range(4):
pixel = (int(time_matrix[i][0]), time_matrix[i][1][j], int(time[i][j]))
x, y, brightness = pixel
display.pixel(x, y, brightness)
display.show()
while True:
display_time()
sleep(60)