
Originally Posted by
Darrel Taylor
That looks pretty good Malc.
And nope, you don't need arrays for the flag bits.
I don't think you should have anything in the AlwaysOFF section, since the CheckTimes routine just determines if it's inside the program period or not.
With multiple time periods, whatever is in AlwaysOFF would happen to both periods if only triggered in one of them.
Any actions can be done after returning from the subroutine.
Something like this in the main loop maybe.
Code:
fn = 0 ; select the first Lights
GOSUB CheckTimes ; compare the programed period
IF ProgON THEN ; If in the program period
IF Lights1 = 0 THEN Lights1 = 1 ; Turn light on (if off)
ELSE
IF Lights1 = 1 THEN Lights1 = 0
ENDIF
; -----------------------------------
fn = 1 ; select the second Lights
GOSUB CheckTimes ; compare the programed period
IF ProgON THEN
IF Lights2 = 0 THEN Lights2 = 1
ELSE
IF Lights2 = 1 THEN Lights2 = 0
ENDIF
Darrel,
Just ripped the LCD out of the unit so I could test this. So far it seems to work apart from one strange thing, the timings are a minute out... If I set the lighting period to come on at 15:00 it comes on at 15:01, and set to off at 15:05 it goes of 15:06, and I don't get anything displayed on the LCD
Here's the code that turns the lights on or off:
Code:
fn = 1 ; select the second Lights
GOSUB CheckTimes ; compare the programed period
IF ProgON THEN
IF Lights2 = 0 THEN Lights2 = 1
LCDOut $FE, $94+9,"Light 2 ON"
ELSE
IF Lights2 = 1 THEN Lights2 = 0
LCDOut $FE, $94+9," "
ENDIF
if Lights1 = 1 and Lights2 = 1 then
LCDOut $FE, $94+9,"Lights ON"
ELSE
LCDOut $FE, $94+9," "
Endif
then there's the checking routine:
Code:
CheckTimes:
TimeCmpFlags = 0 ; clear flags first
; if the Start and Stop times are the same, then Always OFF
if (lightsetHR[fn]=timeH) AND _
(lightsetMN[fn]=timeM) then AlwaysOFF
; is it past the Start time?
if (timeH>lightsetHR[fn]) OR _
(timeH=lightsetHR[fn] AND timeM>lightsetMN[fn])then PastStart=1
; is it past the Stop time?
if (timeH>lightoffHR[fn]) OR _
(timeH=lightoffHR[fn] AND timeM>lightoffMN[fn])then PastStop=1
; does the period end the following day?
if (lightoffHR[fn]< lightsetHR[fn]) OR _
(lightoffHR[fn]=lightsetHR[fn] AND lightoffMN[fn] < lightsetMN[fn]) then NextDay[fn]=1
if !NextDay then ; same day, use AND
if PastStart AND !PastStop then ProgON = 1
else ; next day, use OR
IF PastStart OR !PastStop then ProgON = 1
endif
AlwaysOFF:
return
And finally the section where the time is set:
Code:
Lighting:
Lighton:
Lcdout $FE,2
LCDOUT $FE,$80,"Set On Time For "
IF H_butt = 0 THEN GOSUB IncHours
IF M_butt = 0 THEN GOSUB IncMinutes
lightsetHR[fn]=Hours
lightsetMN[fn]=Minutes
if viv >=2 then viv =2
LCDOUT $FE,$C0,"Light Circuit ",#viv
lcdout $FE,$94,#lightsetHR[fn] DIG 1,#lightsetHR[fn] DIG 0,":",#lightsetMN[fn] DIG 1,#lightsetMN[fn] DIG 0
pause 200
If S_butt = 0 then
pause 250
fn = fn +1
viv = viv+1
hours = 0
minutes = 0
endif
If fn > 1 then
LCDOUT $FE,1
viv=1
fn=0
goto lightoff
endif
goto lighton
lightoff:
Lcdout $FE,2
LCDOUT $FE,$80,"Set Off Time For "
IF H_butt = 0 THEN GOSUB IncHours
IF M_butt = 0 THEN GOSUB IncMinutes
lightoffHR[fn] = Hours
lightoffMN[fn] = Minutes
if viv >=2 then viv =2
LCDOUT $FE,$C0,"Light Circuit ",#viv
lcdout $FE,$94,#lightoffHR[fn] DIG 1,#lightoffHR[fn] DIG 0,":",#lightoffMN[fn] DIG 1,#lightoffMN[fn] DIG 0
pause 200
If !S_butt then
pause 250
fn = fn +1
viv = viv +1
hours = 0
minutes = 0
endif
If fn >=2 then
LCDOUT $FE,1
goto mainmenu
endif
goto lightoff
The subs for inc hrs or mins:
Code:
IncHours:
Hours = Hours + 1
IF Hours = 24 THEN Hours = 0
pause 250
RETURN
IncMinutes:
Minutes = Minutes + 1
IF Minutes = 60 THEN Minutes = 0
pause 250
RETURN
Any ideas....??
Bookmarks