This library (called rSoftRtc), is a generic derivative of the device specific library rESP8266rtc v1-03.
It is a software based Real Time Clock.
You don't need any additional hardware modules.
It does NOT run any special background code to keep the RTC alive.
It can generate Alarm Events at required Date/Times.
It also contains several functions to simplify the manipulation of date/times as seconds.
It gets it's timing by calibrating the millis() function available from Arduino.
Generated Alarm Events are managed by the B4R Scheduler class.
The above example has been revised.
Notes: My testing over several days showed a loss of 1 to 2 sec per day. The RTC could be set (SetClock) every week or so. As the Arduino Millis() function can only count continuously for about 40days the RTC should be set at least once a month.
Now updated to v1.02
see posting below for version details
It is a software based Real Time Clock.
You don't need any additional hardware modules.
It does NOT run any special background code to keep the RTC alive.
It can generate Alarm Events at required Date/Times.
It also contains several functions to simplify the manipulation of date/times as seconds.
It gets it's timing by calibrating the millis() function available from Arduino.
Generated Alarm Events are managed by the B4R Scheduler class.
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
Sub Process_Globals
Public Serial1 As Serial
Private DT(8) As Byte
Private rtc As SoftRtc
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
rtc.Initialize("rtc_Alarm",True)
log("RTC Initialised")
'date .. 10th March 2017 (GMT)
DT(0) = 21 '21st century (ie 2000)
DT(1) = 17 'year
DT(2) = 3 'month
DT(3) = 10 'day
'time .. 1:26pm (zero sec) (GMT)
DT(4) = 13 'hour (0-23)
DT(5) = 26 'minute
DT(6) = 0 'seconds
DT(7) = 0 'not required.
rtc.SetClock(DT,8,0) 'offset for Western Australia. DT +08:00
log("RTC is set")
Log(rtc.ReadClock(DT))
Log("RTC: ",DT(0),",",DT(1),",",DT(2),",",DT(3),",",DT(4),",",DT(5),",",DT(6),",",DT(7))
rtc.SetAlarm(1,rtc.Sec2DT(rtc.DT2Sec(DT)+10))
rtc.SetAlarm(2,rtc.Sec2DT(rtc.DT2Sec(DT)+5))
rtc.SetAlarm(3,rtc.Sec2DT(rtc.DT2Sec(DT)+15))
rtc.SetAlarm(9,rtc.Sec2DT(rtc.DT2Sec(DT)+rtc.SECONDS_1MINUTE))
Log("RTC is running")
End Sub
private Sub rtc_Alarm(index As Byte)
If index=0 Then
'tick every second
rtc.ReadClock(DT)
Log("RTC: ",rtc.ShortDOW(DT),", ",rtc.ShortDate(DT),", ",rtc.Time24(DT))
Return
End If
Log("AlarmEvent: ",index)
End Sub
The above example has been revised.
Notes: My testing over several days showed a loss of 1 to 2 sec per day. The RTC could be set (SetClock) every week or so. As the Arduino Millis() function can only count continuously for about 40days the RTC should be set at least once a month.
Now updated to v1.02
see posting below for version details
Attachments
Last edited: