'''
PROJECT 12: REAL-TIME CLOCK (RTC)
The ESP32 has a built-in RTC that can be used as to keep time. Once the time and date is set
the RTC will contnue to maintain the time, date, etc as long as power to the ESP32 device is
maintained.
Components
----------
Documentation:
RTC: https://docs.micropython.org/en/latest/esp32/quickref.html#real-time-clock-rtc
'''
from machine import RTC,Pin
from time import sleep_ms
UP = "\x1B[5A"
CLR = "\x1B[0K"
rtc = RTC()
led_flash = Pin(5,Pin.OUT)
# Datetime is a tuple of the form:
# (year, month, day, weekday, hours, minutes, seconds, subseconds)
# weekday and subseconds can be left 0
# Example: 26th of September 2022, 10:00
rtc.datetime((2022, 9, 26, 0, 12, 00, 00, 0)) # set a specific date and time
while True:
date_time = rtc.datetime()
print(UP,"Year: ",date_time[0],
CLR ,"\n","Month:",date_time[1],
CLR ,"\n","Day: ",date_time[2],
CLR ,"\n","Time: ",date_time[4],"H:",date_time[5],"M:",date_time[6],"S:",
CLR ,"\n")
led_flash.value(not led_flash.value())
sleep_ms(1000)