I want to turn on and off the SW12 switch with 20/20 minute cycle. Is this will continuously work? I want to make sure about this code.
BeginProg
Scan (1,Sec,0,0)
If TimeIntoInterval(0,40,Min) Then SW12(1)
If TimeIntoInterval(20,40,Min) Then SW12(0)
NextScan
EndProg
The code you posted will definitely work.
It shows the simplicity of using TimeIntoInterval.
Following is an alternative way.
With this method, even if you happen to skip a scan or happen to go through a power cycle / reboot, the logger will still get a chance to turn SW12V high during the first 20 min of a 40 min cycle and low during the last 20 min of a 40 min cycle.
Public SecIntoDay As Long
Public TwentyMin = 20*60
Public FortyMin = 40*60
BeginProg
Scan (1,Sec,0,0)
SecIntoDay = Public.Timestamp(4,1)
If (SecIntoDay MOD FortyMin) < TwentyMin Then
SW12 (1 )
Else
SW12(0)
EndIf
NextScan
EndProg