machine.RTC.rst 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. .. currentmodule:: machine
  2. .. _machine.RTC:
  3. class RTC -- real time clock
  4. ============================
  5. The RTC is and independent clock that keeps track of the date
  6. and time.
  7. Example usage::
  8. rtc = machine.RTC()
  9. rtc.init((2014, 5, 1, 4, 13, 0, 0, 0))
  10. print(rtc.now())
  11. Constructors
  12. ------------
  13. .. class:: RTC(id=0, ...)
  14. Create an RTC object. See init for parameters of initialization.
  15. Methods
  16. -------
  17. .. method:: RTC.init(datetime)
  18. Initialise the RTC. Datetime is a tuple of the form:
  19. ``(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])``
  20. .. method:: RTC.now()
  21. Get get the current datetime tuple.
  22. .. method:: RTC.deinit()
  23. Resets the RTC to the time of January 1, 2015 and starts running it again.
  24. .. method:: RTC.alarm(id, time, \*, repeat=False)
  25. Set the RTC alarm. Time might be either a millisecond value to program the alarm to
  26. current time + time_in_ms in the future, or a datetimetuple. If the time passed is in
  27. milliseconds, repeat can be set to ``True`` to make the alarm periodic.
  28. .. method:: RTC.alarm_left(alarm_id=0)
  29. Get the number of milliseconds left before the alarm expires.
  30. .. method:: RTC.cancel(alarm_id=0)
  31. Cancel a running alarm.
  32. .. method:: RTC.irq(\*, trigger, handler=None, wake=machine.IDLE)
  33. Create an irq object triggered by a real time clock alarm.
  34. - ``trigger`` must be ``RTC.ALARM0``
  35. - ``handler`` is the function to be called when the callback is triggered.
  36. - ``wake`` specifies the sleep mode from where this interrupt can wake
  37. up the system.
  38. Constants
  39. ---------
  40. .. data:: RTC.ALARM0
  41. irq trigger source