Time comparison


Results 1 to 21 of 21

Thread: Time comparison

Threaded View

  1. #1
    malc-c's Avatar
    malc-c Guest

    Default Time comparison

    Hi guys and gals,

    Can someone offer some suggestions as to how to determine if when setting the on / off times for some lights, the lights should be on at the time of applying the settings.

    I'm using a 1307 RTC and have the following within the code

    Code:
    If lightsetHR[fn]=timeH and lightsetMN[fn]=timeM then         'compare value of each set time to current time and if matches
       if fn=0 then Lights1 = 1
       if fn=1 then Lights2 = 1                              'turn on those light
       LCDOut $FE, $94+9,"Lights ON"
    endif
    
    If lightoffHR[fn]=timeH and lightoffMN[fn]=timeM then         'compare value of each start time to current time and if matches
       if fn=0 then Lights1 = 0
       if fn=1 then Lights2 = 0                            'turn off the light
       if lights1 = 0 and lights2 = 0 then
       LCDOut $FE, $94+9,"          " 
    endif
    If the current time is say 12:15 and I set the lights to come on at say 12:20 and then go off at 12:25 it works perfectly, however, if the current time is 12:22 and I try to set the time the lights remain off... presumably until 12:20 the next day. I'm looking for a simple way for the code to work out if the time of setting the lighting period whether or not the lights should be on or not.

    Here is the section where the user sets the on/off times

    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
    Last edited by malc-c; - 24th July 2010 at 13:22. Reason: added more code

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts