A user wrote today with a small example to turn an output on with a schedule and off depending on the state of an input. The program they submitted has a goto and some tricky logic, I suggested some small changes to simplify it and posted here so others can learn:
I am trying to do this very simple program and I don’t know why it doesn’t work. The prog file is attached, here is the code:
10 IF SCH1 THEN START OUT7
20 IF TIME-ON ( OUT7 ) > 00:30:00 THEN GOTO 30
30 IF IN1 > 1 THEN START OUT7
The problem is that out7 starts when sch1 is off because in1>1 but it stops when in1<1…I want that out7 still on for 30 minutes after in1 becames from >1 to <1.
So its basically a momentary light switch with schedule and after hours override.
VAR1 : TIME LEFT FOR OVERRIDE TIMER
VAR2 : AFTER HOURS OVERRIDE INTERVAL
10 IF SCH OR VAR1 > 0:0:0 THEN START OUT5 ELSE STOP OUT5
20 IF+ IN1 THEN VAR1 = VAR2
30 IF INTERVAL( 0:0:01 ) AND VAR1 > 0:0:0 THEN VAR1 = VAR1 - 0:0:01
Notes: the IF+ statement resets the timer to the full override time interval. Use IF+ to do it on the rising edge, single event. You could do it with a regular IF but the IF+ will let the timer start decrementing immediately after a button press even if the button is still held down, subtle difference but why not.
The VAR1 timer shows how much time is left before the lights go off, add these to your graphical floorplans so you can see at a glance how long till the lights go off.
The VAR2 override interval can also be placed on the user graphical interface to let the building operator adjust the amount of time the lights will be on for each hit on the switch.