Time comparison


Closed Thread
Results 1 to 21 of 21

Thread: Time comparison

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Malcolm,

    I missed this part in your conversion last time.
    Code:
         ; if the Start and Stop times are the same, then Always OFF 
      if (lightsetHR[fn]=timeH) AND _       
         (lightsetMN[fn]=timeM) then AlwaysOFF
    It should be testing the Stop time instead of the Current time.

    Here's the updated code.
    Code:
    CheckTimes:
    TimeCmpFlags = 0  ; clear flags first
    
         ; if the Start and Stop times are the same, then Always OFF 
      if (lightsetHR[fn]=lightoffHR[fn]) AND _       
         (lightsetMN[fn]=lightoffMN[fn]) 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
    
      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
    I've run it in the simulator and it works perfectly.

    Name:  TimeCompare.JPG
Views: 514
Size:  152.7 KB
    DT

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


    Did you find this post helpful? Yes | No

    Default

    Thanks guys,

    Darrel, I'll give that a whirl later this morning.... and will report back if I have any issues

    Love the look of that simulator.... nice layout

    Thanks for the support

    Edit - Just tried it by setting the current time to 8:15 and then setting the lighting to come on at 8:09 and off at 8:20 and when run it works fine - have also tried it with the clock set to 23:58 and a lighting period of 23:59 to 00:01 and that works too - Thanks DT

    However.....

    I can't get the display to show when the lights are on...

    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
           IF Lights1 = 1 LCDOut $FE, $94+9,"Light 1 ON"
        ELSE
           IF Lights1 = 1 THEN Lights1 = 0
           IF Lights1 = 0 LCDOut $FE, $94+9,"          " 
        ENDIF
    
        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
    The value for Lights1 or Lights2 changes from 0 to 1 as the corresponding LED on the development board lights up or turns off according to the value, but the IF Lights1 = 1 LCDOut $FE, $94+9,"Light 1 ON" or IF Lights1 = 1 THEN LCDOut $FE, $94+9,"Light 1 ON" seems to be ignored
    Last edited by malc-c; - 28th July 2010 at 09:17. Reason: update - feedback on performance

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