Weird Issue With My Lights Timer
Lightfoot
Posts: 228
I converted the clock in the Labs Manual to function as a light timer. The light timer is just one of many subroutines I have for my XBEE holiday lights animator project. A separate function sets the clock over the serial port to the current PC time. 24 hour time is used in this application. The on and off times are set for each of my 6 animator units (see my XBee network post in the sandbox for more info) in the arrays. Every time the minute value increases, the timer checks each animator's set on and off time to see if a match is found. If one is found, the animator will either turn on or off. The code works except that it does not turn on or shut off the animators after somewhere beyond between 5 and 10 minutes. So, for example if the time is 10:30AM and the animators are set to turn on at 10:32, the animators will turn on. If you set the time to 10:40, they will not turn on. The same applies for the off cycle. Here is the code for the clock timer. Is there something with the clock or is the bug coming from outside the clock routine? The clock runs in its own cog.
Don't mind the italics in the code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'****************************************** Clock: ********************************************* 'Clock keeps track of the time. PRI Clock | i, clkfrequency, ticks clkfrequency := clkfreq ticks := cnt repeat ticks += clkfrequency waitcnt(ticks) seconds++ if seconds // 60 == 0 'Tabulate minutes. minutes++ if minutes == 60 minutes := 0 repeat i from 0 to numOfAnimators - 1 'Check each animator to see if it is due on or off. if hours == onHours[i] and minutes == onMinutes[i] MGR.TransmitCommand(i + 1, "O") 'Transmit on command to animator. if hours == offHours[i] and minutes == offMinutes[i] MGR.TransmitCommand(i + 1, "F") 'Transmit off command to animator. if seconds // 3600 == 0 'Tabulate hours. hours++ if hours == 24 hours := 0 [/i][/i][/i][/i]
Don't mind the italics in the code.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Comments
I'm not sure that's the problem as you use // 3600 meaning it's at least a word but it's something you should think about.
You've got italics in your code, because a [noparse][[/noparse]i] subscript got zapped and interpreted as an italics tag. To eliminate this problem, use my code formatter at:
www.phipi.com/format
Now, why not use something like this:
I wasn't sure whether "++seconds //= 60" would work or not, else I'd have recommended it as a further shorthand.
-Phil