from machine import I2C, Pin
from utime import sleep_ms
from hcsr04 import HCSR04
from ssd1306 import SSD1306_I2C
import ds1307
Ho = Pin(32, Pin.IN)
i2c = I2C(sda=Pin(21), scl=Pin(22))
ds = ds1307.DS1307(i2c)
oled = SSD1306_I2C(128, 32, i2c)
#now = (2018, 8, 8, 2, 13, 45, 0) #Year Munt monthday weekday Hour Minute second
#ds.datetime(now)
ds.datetime()
mont=("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC")
DayOfWeek = ("Mon","Tue","Wed","Thu","Fri","Sat","Sun")
while True:
DT = ds.datetime()
print(DT)
oled.fill(0)
if(Ho()==0):
sleep_ms(1000)
Y = DT[0]
M = DT[1]
D = DT[2]
DW = DT[3]
H = DT[4]
M = DT[5]
S = DT[6]
H += 1
if(H>=24):
H=0
now = (Y, M, D, DW, H, M, S)
ds.datetime(now)
oled.text(DayOfWeek[DT[3]-1],0,0)
oled.text(str(DT[2]), 30, 0)
oled.text(mont[DT[1]-1], 45, 0)
oled.text(str(DT[0]), 75, 0)
oled.text(str(DT[4]), 30, 20)
oled.text(':', 45, 20)
oled.text(str(DT[5]), 50, 20)
oled.text(':', 65, 20)
oled.text(str(DT[6]), 70, 20)
oled.show()
sleep_ms(100)