Shop OBEX P1 Docs P2 Docs Learn Events
Help needed on Hour-meter — Parallax Forums

Help needed on Hour-meter

osullosull Posts: 4
edited 2009-08-31 16:25 in Propeller 1
Hi

How do you encorperate an hour meter in spin code? I just want to be able to keep track of the minutes and hours while powered on and display it to an LCD screen. I know how to display it. But I do not know how to set up the variables to count the minutes or hours while running.

Dermot

Comments

  • Bobb FwedBobb Fwed Posts: 1,119
    edited 2009-08-31 16:25
    Here this does everything (seconds, minutes, hours, days):

    VAR
    
      BYTE seconds, minutes, hours
      WORD days                     ' 179 years 
    
    PUB Clock | wait
    
      wait := cnt
      REPEAT                        ' repeat forever
        waitcnt(wait += clkfreq)
        seconds++
        IF (seconds => 60)
          seconds~
          minutes++
          IF (minutes => 60)
            minutes~
            hours++
            IF (hours => 24)
              hours~
              days++
    
    


    If you want to do code that counts time without making a cog exclusive to counting time (integrating it into an existing loop)...I have code for that too, but this one is simpler to implement.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    April, 2008: when I discovered the answers to all my micro-computational-botherations!

    Post Edited (Bobb Fwed) : 8/31/2009 4:30:21 PM GMT
Sign In or Register to comment.