Shop OBEX P1 Docs P2 Docs Learn Events
SPIN newbie needs help with REPEAT UNTIL — Parallax Forums

SPIN newbie needs help with REPEAT UNTIL

Here is the code I've got so far (snip of the pertinent section):
text.Start(12)
pst.StartRxTx(9,6,0,2_400)
BYTEFILL(@inbuf,0,bufsize)
repeat until inbuf[0] == $24
pst.StrIn(@inbuf) ' read the rxpin until CR encountered.
' repeat
WindSpeed
Temperature
WindDir
RainGuage

What I'm expecting is for the four routines to display Speed, Temp, Dir & Rain only when there is a valid read of the serial port (looking for "$"). Otherwise I want the program to just sit and wait for the incoming "$". The way it's written now, I get one pass through the program and no more. I'm confused with the nesting of the REPEAT commands.

Comments

  • Please put your program in [ code ] [ /code ] tags (without the blanks) in order to preserve indentation. Then we'll have a better idea of what it's supposed to do.

    -Phil
  • AribaAriba Posts: 2,690
    Or just click on the big C in the icons above the edit field, and paste the code in.
    repeat until inbuf[0] == $24
    
    can only work if another cog overwrites inbuf[0], but I think that is not the case here.
    so you need something like that:
      repeat
         inpuf[0] = pst.CharIn
      until inbuf[0] == $24
    

    or simpler:
    repeat until pst.CharIn == $24
    

    Andy
  • PUB Main
      nbr.init
      DIRA[2..0] := %111 ' Set as outputs.
      DIRA[23..16] := %11111111 ' Set as outputs
      text.Start(12)
      pst.StartRxTx(9,6,0,2_400)
      BYTEFILL(@inbuf,0,bufsize)
      repeat until inbuf[0] == $24 
        pst.StrIn(@inbuf)   ' read the rxpin until CR encountered.
    '   repeat
        WindSpeed
        Temperature
        WindDir
        RainGuage
    

    This is the code for Main.
  • Mike GreenMike Green Posts: 23,101
    edited 2016-02-27 05:45
    How about
      repeat
        pst.StrIn(@inbuf)
        if inbuf[0] == $24
          WindSpeed
          Temperature
          WindDir
          RainGauge
    
    You want to keep reading lines from the serial terminal indefinitely which .StrIn does for you. If a line starts with "$" you want to display stuff. That's all. The initialization stuff is the same.
  • Thank you Mike! That works great!
Sign In or Register to comment.