/ examples / featherwing_rtc_simpletest.py
featherwing_rtc_simpletest.py
 1  """
 2  This example will allow you to set the date and time
 3  and then loop through and display the current time
 4  """
 5  import time
 6  from adafruit_featherwing import rtc_featherwing
 7  
 8  days = ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
 9  
10  # Create the RTC instance:
11  rtc = rtc_featherwing.RTCFeatherWing()
12  
13  # pylint: disable-msg=using-constant-test
14  if True:  # Change this to True to set the date and time
15      rtc.set_time(13, 34)  # Set the time (seconds are optional)
16      print(rtc.now)
17      rtc.set_date(16, 1, 2016)  # Set the date
18      print(rtc.now)
19      rtc.year = 2019  # Set just the Year
20      print(rtc.now)
21      rtc.month = 2  # Set Just the Month
22      print(rtc.now)
23      rtc.hour = 16  # Set just the hour
24      print(rtc.now)
25      rtc.weekday = 6  # Set just the day of the week (Sunday = 0)
26      print(rtc.now)
27      rtc.unixtime = 1550335257  # Or set the date and time with a unix timestamp
28  
29  # Main loop:
30  while True:
31      now = rtc.now
32      print(
33          "The date is {} {}/{}/{}".format(
34              days[now.weekday], now.day, now.month, now.year
35          )
36      )
37      print("The time is {}:{:02}:{:02}".format(now.hour, now.minute, now.second))
38      print("The UNIX timestamp is {}".format(rtc.unixtime))
39      print("The number of days in the current month is {}".format(rtc.get_month_days()))
40      if rtc.is_leap_year():
41          print("This year is a leap year")
42      else:
43          print("This year is not a leap year")
44      time.sleep(1)  # wait a second