Shop OBEX P1 Docs P2 Docs Learn Events
RCtime decay — Parallax Forums

RCtime decay

stilgarstilgar Posts: 47
edited 2012-05-04 16:17 in Propeller 1
I am having trouble getting this code to stop when r_time reaches a number. for this example "5".
I think I should use "case" but I still don't understand how to use it.

any help to understand the case command in this example would greatly be appreciated.

thanks
stilgar

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-05-04 09:00
    I'm not really sure what you mean by wanting the program to "stop".

    You don't really need to use case in the example. A simple if statement is enough to check for equality.

    Indentation is part of the Spin syntax. It's confusing when you add apparently random indentations.

    I changed the end of the program to this.
      repeat      
        term.dec(rtime/1200)
        term.str(string("     ",CR))
        if rtime/1200 == _NumberToMatch
          term.str(string("rtime/1200= "  ))
          term.dec(_NumberToMatch)
          term.str(string(CR, "Program is over."  ))
            repeat ' ends program but keeps cog alive
    

    I added a constant "_NumberToMatch" in the CON section.
    con 
      #1, HOME, #8, BKSP, TAB, LF, CLREOL, CLRDN, CR, #16, CLS      ' PST formmatting control
      _NumberToMatch = 5
      
    
    

    I think the above changes should make the program stop once rtime/1200 equals five.

    It's not a pretty way to end a program (while still inside a loop) but I didn't want to add any more code than absolutely necessary.

    Edit: I'm not sure why r_time is used. In the attached code the loop continuously displays r_time but rtime is the variable being updated.
  • stilgarstilgar Posts: 47
    edited 2012-05-04 16:17
    Thanks, the new code works much better. I am still confused about the IF or CASE choice, the books I have say CASE is more efficient, but I am still learning.
Sign In or Register to comment.