-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
31 lines (24 loc) · 754 Bytes
/
main.py
File metadata and controls
31 lines (24 loc) · 754 Bytes
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
import time
import board
import digitalio
import rtc
import ds1302
# Define the clock, data and enable pins
clkpin = digitalio.DigitalInOut(board.D10)
datapin = digitalio.DigitalInOut(board.D11)
cepin = digitalio.DigitalInOut(board.D12)
# Instantiate the ds1302 class
ds1302 = ds1302.DS1302(clkpin,datapin,cepin)
# Now, let us set the time
the_time = time.struct_time((2018,10,22,10,34,30,1,-1,-1))
ds1302.write_datetime(the_time)
# Redefine the RTC class to link with the ds1302
class RTC(object):
@property
def datetime(self):
return ds1302.read_datetime()
# Instantiate the rtc class and set the time source
r = RTC()
rtc.set_time_source(r)
# With this in place, you can now call the following to get the time!
time.localtime()