Shop OBEX P1 Docs P2 Docs Learn Events
Weird Issue With My Lights Timer — Parallax Forums

Weird Issue With My Lights Timer

LightfootLightfoot Posts: 228
edited 2010-06-30 05:55 in Propeller 1
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.

'****************************************** 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

  • kuronekokuroneko Posts: 3,623
    edited 2010-06-30 05:11
    You keep incrementing the seconds but never reset them (or at last keep them at 60n). If seconds is e.g. a byte then you will run into trouble (each step is +60):

    0..60..120..180..240..44
    


    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.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2010-06-30 05:55
    Lightfott,

    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:

    seconds++
    [b]ifnot[/b] (seconds //= 60)
      minutes++
      [b]ifnot[/b] (minutes //= 60)
        hours := (hours + 1) // 24
    
    
    


    I wasn't sure whether "++seconds //= 60" would work or not, else I'd have recommended it as a further shorthand.

    -Phil
Sign In or Register to comment.