Shop OBEX P1 Docs P2 Docs Learn Events
(NEED HELP) I need the code for a digital clock using just the DEBUG TERMINAL SCREEN — Parallax Forums

(NEED HELP) I need the code for a digital clock using just the DEBUG TERMINAL SCREEN

Using no components just the basic stamp and computer.
Design code to display time onto the terminal screen.
Need to be able to set anytime and have it go through the cycle.

@xanadu

Comments

  • Welcome aboard.

    Can you post the code you have so far?
  • evan79491evan79491 Posts: 9
    edited 2016-12-13 01:42
    I am relatively new to all this coding so i am kinda wondering how i should even start because i am way off right now.

    So i have pretty much not really gotten far at all i just dont know what i am supposed to use.

    I have this right now but this is like the 5th thing i have started lol i just really need help in general

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    secs VAR Byte '
    mins VAR Byte '
    hrs VAR Byte '
    startVal VAR Byte
    endVal VAR Byte

    Setup:
    startVal = 1
    endVal = 60
    mins =1

    Main:

    FOR secs = startVal TO endVal
    PAUSE 1000

    DEBUG CRSRXY, 100, 12, DEC secs, CR
    DEBUG CRSRXY, 98, 12, DEC mins, CR

    IF (secs = 60) THEN
    startVal = 1
    endVal = 60
    DEBUG CRSRXY, 98, 12, DEC mins +1, CR

    ENDIF


    NEXT
  • I mean if you or somebody could figure it out I would be so thankful haha I have a final next week and I need to know how to do this.
  • It looks like you have minutes and seconds.
    DEBUG CRSRXY, 98, 12, DEC mins = DEC mins + 1
    

    End this line of code like the lines above it, increment your mins var on the next line. Then you can add hours after it.

  • Do you think you could help me finish I am still not getting it
  • The mins part will turn from 1 to 2 for only a sec and you also need to be able to do like 1:01
  • xanaduxanadu Posts: 3,347
    edited 2016-12-13 16:28
    You are on the right track. There are a lot of ways to do this. There are probably better examples than this. I had made a clock and found it in the archives. When I'm stuck I look at other people's work, just keep in mind you can't use it for the final.

    Here is a simple example using IF/THEN. There are cleaner ways to do this, but this is the easiest to
    understand IMO. Now you can apply the same thing to what you have. -
    DO
    secs = secs + 1                       'clock interval, normally 1 (changing will break am/pm)
    PAUSE 970                             'loop execution offset ~970 for updating terminal
    IF secs = 60 THEN mins = mins + 1     '60 seconds passed
    IF secs = 60 THEN secs = 0            'reset seconds
    IF mins = 60 THEN hours = hours + 1   '60 minutes passed
    IF mins = 60 THEN mins = 0            'reset minutes
    IF hours = 13 THEN hours = 1          '12h time format
    IF hours = 11 AND mins = 59 AND secs = 59 THEN GOSUB tampm 'toggle AM PM
    GOSUB update                          'update display
    LOOP
    

    I start a loop for seconds, and then pause for just under a second to compensate for the rest my code. When the seconds equal 60, minutes go up, and then seconds are reset. When minutes are 60 hours go up and minutes are reset. When hours hit 13 we reset them to 1. When it's 11 hours and 59 minutes and 59 seconds we can toggle AM/PM status.

    When you output to the terminal you don't need the ",CR" (carriage return) at the end when using CRSRXY. I would setup the display first, this would only run once:
    reset:
    DEBUG CRSRXY, 1, 0, "Basic Stamp II Clock" 'setup terminal
    DEBUG CRSRXY, 1, 2, DEC2 hours
    DEBUG CRSRXY, 3, 2, ":"
    DEBUG CRSRXY, 4, 2, DEC2 mins
    DEBUG CRSRXY, 6, 2, ":"
    DEBUG CRSRXY, 7, 2, DEC2 secs
    IF ampm = 1 THEN DEBUG CRSRXY, 10, 2, "PM"
    IF ampm = 0 THEN DEBUG CRSRXY, 10, 2, "AM"
    return
    

    Then I would run the timing loop and update the display like this. You will notice DEC2 that will format the number as two digits, 2 = 02, which makes it feel more like a clock to me.
    update:
    DEBUG CRSRXY, 1, 2, DEC2 hours        'print hours in 2 digit format
    DEBUG CRSRXY, 4, 2, DEC2 mins         'print mins in 2 digit format
    DEBUG CRSRXY, 7, 2, DEC2 secs         'print secs in 2 digit format
    return
    

  • Lose the FOR/NEXT. Change to a DO/LOOP
    DO
      PAUSE "somewhat less than 1000"
      Secs = Secs + 1
      IF Secs = 60 THEN
       Secs = 0
       Mins = Mins + 1
       If Mins = 60
         Mins = 0
         Hrs = Hrs + 1
         ENDIF
       ENDIF
      DEBUG DEC Hrs, ":", DEC Mins, ":", DEC Secs, CR
      LOOP
    
    
  • When you have that part figured out, this is a great explanation of serial input -

    http://www.parallax.com/go/PBASICHelp/Content/LanguageTopics/Commands/SERIN.htm

    Toward the bottom you will see usage examples.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    This is an old thread and uses the DS1302, however the code included is set and displayed on the DEBUG screen.

    http://forums.parallax.com/discussion/77867/ds1302-demo-code-updated
  • You guys are so helpful thank you very much.....sorry I did not get back to you been busy with family issues but I appreciate the help very much so does @xanadu does that code do the whole thing, I'll be sure to not use yours but just so I know how to read your code so when I make my own?
  • But thank you guys all of you big help a lot of input I love this forum
  • @xanadu how do i set the time for this code
  • nvm i got it thanks!!!!
  • Outstanding. Nice work.
Sign In or Register to comment.