What about
Or am I missing something??Code:If lightsetHR[fn] >= timeH and lightsetMN[fn] >= timeM then
What about
Or am I missing something??Code:If lightsetHR[fn] >= timeH and lightsetMN[fn] >= timeM then
Dave
Always wear safety glasses while programming.
Hi Dave,
That's what I thought.. but it doesn't work because of the checking of the minutes. For example, if the current time is 18:07 and I want to set the on time to 16:45 then I tried
I used < because in this case lightsetHR = 16 and timeH=18. But as lightsetMN = 45 and timeM is 07 the condition is not matched. If used as per your example,Code:If lightsetHR[fn] <= timeH and lightsetMN[fn] <= timeM then
lightsetHR =16 which isn't > than timeH which is 18 so again the condition would not be matchedCode:If lightsetHR[fn] >= timeH and lightsetMN[fn] >= timeM then
Does that make sense ?
I still think this rountine is your best bet.
http://www.picbasic.co.uk/forum/show...8913#post58913
It takes a Start Time (H:M:S) and End Time, then tells you if it's within that time period or not. Even if the period ends the following day.
DT
Hi Darrel,
I've not had chance to test this yet, but here's how I've adapted the code
The one thing I'm not too clear on, given that I have two sets of start times and end times for the two lighting circuits, do I need to change the PastStop and Paststart to something like PastStop[fn] and PastStart[fn] to match the same lightoff[nf] etc ?Code: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=1 ' endif ;--------------- 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: Lights1 = 0 Lights2 = 0 'turn off the light if lights1 = 0 and lights2 = 0 then LCDOut $FE, $94+9," " endif return
The following compiles, but I'm not able to test yet as I'm waiting for a 20 x 4 LCD
Code: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[fn]=1 ; is it past the Stop time? if (timeH>lightoffHR[fn]) OR _ (timeH=lightoffHR[fn] AND timeM>lightoffMN[fn])then PastStop[fn]=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 ' endif ;--------------- if !NextDay then ; same day, use AND if PastStart[fn] AND !PastStop[fn] then ProgON = 1 else ; next day, use OR IF PastStart[fn] OR !PastStop[fn] then ProgON = 1 endif if fn=0 and ProgON=1 then Lights1 = 1 LCDOut $FE, $94+9,"Lights ON" if fn=1 and ProgOn=1 then Lights2 = 1 'turn on those light LCDOut $FE, $94+9,"Lights ON" AlwaysOFF: Lights1 = 0 Lights2 = 0 'turn off the light if lights1 = 0 and lights2 = 0 then LCDOut $FE, $94+9," " endif return
I must be having one of those days...
I still do not get why something like this will not work.
If current time is equal to or greater than set start time then on.
If current time is equal to or greater than set stop time then off.
Add some vars here and there for two lights...
Use if/then s. Case while/wend ....
Dave
Always wear safety glasses while programming.
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
DT
Thanks Darrel,
Hopefully the LCD will arrive soon and I'll be able to test this on the development board![]()
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:
then there's the checking routine: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
And finally the section where the time is set: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
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:
Any ideas....??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
Malcolm,
In the original CheckTimes: routine, the Seconds test had a >=.
That way it's TRUE when the exact second rolls around.
Modified for Minutes as the smallest period, I think the Minutes test now needs the >=
P.S. There's still an Array index in your NextDay flag.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
Last edited by Darrel Taylor; - 26th July 2010 at 22:34. Reason: P.S.
DT
Bookmarks