Timer for Lights

MobileMe

Active Member
I'm trying to figure out a better way to turn on/off a light in my home. I setup a timer using PLC code to turn them on at 5pm and off at 10pm. The problem is my code will not allow me to manually turn the lights off for the entire hour at 5pm and on at 10pm.

Is there a better way to write the code so I can turn the light on/off durning those two hours? I could deal with just a minute of auto on/off, but I'm having trouble writing the code.

START

LOOP:
SET RAM3 CH
TSTEQ RAM3 17
CALLSUB LITEON
TSTEQ RAM3 22
CALLSUB LITEOFF
GOTO LOOP
END

RESETS:
TSTEQ IP8 0
SET RAM8 0
TSTEQ IP8 1
SET RAM8 1
RET

LITEON:
TSTEQ RAM8 0
GOTO LON
RET
LON:
SET OP7 1
DELAY 500
SET OP7 0
SET RAM8 1
RET

LITEOFF:
TSTEQ RAM8 1
GOTO LOFF
RET
LOFF:
SET OP8 1
DELAY 500
SET OP8 0
SET RAM8 0
RET

I use OP1 to let me know if the light is on or off. Keep on mind that this not all of my code. I have all of the boards variables in use.

Thanks
 
Crikey, that's complicated for what you want to do.

I just set up a forced-aspiration temperature sensor, and wanted the fan to run from 4am to 10pm.
This is the code I used, and it works perfectly:

START
TSTGE CH 4 VAR1
TSTGT CH 21
SET VAR1 0
SET OP8 VAR1
END


If you wanted to manually control the lights, lets use VAR2.

VAR2=1 (automatic mode)
VAR2=2 (OFF)
VAR2=3 (ON)

I think this will work:

TSTGE CH 4 VAR1
TSTGT CH 21
SET VAR1 0

TSTGE VAR2 2
ANDB VAR2 1 VAR1

SET OP8 VAR1
 
After posting, I figured it out.

START
TSTEQ CH 17
CALLSUB LITEONM
TSTEQ CH 22
CALLSUB LITEOFFM
END
LITEONM:
TSTEQ CM 0
GOTO LITEONS
RET
LITEONS:
TSTEQ CS 0
GOTO LITEON
TSTEQ CS 1
GOTO LITEON
TSTEQ CS 2
GOTO LITEON
RET
LITEON:
TSTEQ RAM8 0
GOTO LON
RET
LON:
SET OP7 1
DELAY 500
SET OP7 0
SET RAM8 1
RET

I use the same code for the off timer. It seems to work pretty well. The lights will always be on a timer, I don't really need to switch modes from timer to manual. Although it is a good idea that I just might use later on down the road. When I get my board back from CAI, I plan on putting in vars for the current hour and current minute so I can change the times remotely as needed.
 
Back
Top