Shop OBEX P1 Docs P2 Docs Learn Events
BASIC Stamp Variables — Parallax Forums

BASIC Stamp Variables

CorbettROVCorbettROV Posts: 17
edited 2008-11-03 23:01 in BASIC Stamp
Hi, I need to have my BS2 set a variable to zero if it does not hear from the computer for a certain amount of time. How do I do that?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-30 17:50
    It all depends on the context. It depends on what else the Stamp is doing and how it "hears from the computer" now. If the Stamp is just listening for something from the computer via a serial port, you can use the SERIN timeout feature (read the Manual chapter on the SERIN statement). If there's something else going on, you'll have to give details.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-30 17:53
    I have this program running, but I want it to set x to 0 when there is no input through the Debug Terminal. I have it hooked up to the computer continuously via USB.

    [noparse][[/noparse]quote]
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    x VAR Byte
    y VAR Byte
    z VAR Byte
    DO
    SEROUT 0, 84, [noparse][[/noparse]z, x]
    DEBUGIN y
    IF (y=97) THEN
    z=$C6
    x=127
    ELSEIF (y=115) THEN
    z=$C5
    x=127
    ENDIF
    LOOP
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-30 18:20
    Rather than DEBUGIN, use the SERIN statement with a I/O pin # of 16. This is the same as the programming port.
    Use the timeout feature as described in the Manual chapter on the SERIN statement. If the timeout occurs, set x to 0.

    This has some limitations. In particular, if the Debug Terminal sends a character while the Stamp program is doing
    something else (than the DEBUGIN or SERIN), the Stamp will miss the character.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-30 19:02
    So I would change "DEBUGIN y" to "SERIN 16, (baud), [noparse][[/noparse]y]"?

    What would I set as the baud rate?

    And if I use SERIN instead of DEBUGIN, would the debug terminal come up?
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-30 19:20
    Notice in the paragraph near the bottom of page 171 (DEBUGIN) that this is a special case of SERIN with inverted mode, 9600 Baud, 8 bits, 1 stop bit, and no parity. There are tables of Baud constants on page 397 of the Manual. 8 bit, no parity, inverted, 9600 Baud on a BS2 uses 16468 as the Baud constant.

    As far as I know, the Stamp Editor just detects incoming characters and that causes the debug terminal to start.

    Don't forget the timeout time and label.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-30 19:24
    The debug terminal is only starting when I have a DEBUG or DEBUGIN command. So I don't know how to make it accept characters.
  • Carl HayesCarl Hayes Posts: 841
    edited 2008-10-30 21:34
    CorbettROV said...
    The debug terminal is only starting when I have a DEBUG or DEBUGIN command. So I don't know how to make it accept characters.
    You answered this yourself.· Use a single DEBUG, say for example

    ··· DEBUG CR

    in your Stamp program, and Debug will start in the PC.· Then you can type stuff in.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    · -- Carl, nn5i
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-30 22:01
    Ok, so now I have this program, and it isn't doing anything. I think there must be an error with my SERIN command, but I don't know what it is.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    x VAR Byte
    y VAR Byte
    z VAR Byte
    DO
      DEBUG CR
      SEROUT 0, 84, [noparse][[/noparse]z, x]
      SERIN 16, 84, Continue, 2000, Time_Out, [noparse][[/noparse]y]
    
    Continue:
      IF (y=97) THEN
      z=$C6
      x=127
      ELSEIF (y=115) THEN
      z=$C5
      x=127
      ENDIF
    
    Time_Out:
      x=0
    
    LOOP
    
    



    Thanks

    Post Edited (CorbettROV) : 10/30/2008 10:08:20 PM GMT
  • J^3J^3 Posts: 121
    edited 2008-10-31 02:28
    I believe evrything looks good except your baud constant for pin 16.· Try the constant Mike suggested earlier (16468).

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    There are 10 types of people that understand binary, those who do, and those who don't.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-10-31 04:51
    Ah, right. I had it set at 84 because I was testing it in a separate terminal program, which was set at 9600, 8-bit, no parity.

    Thanks, I'll test this out Monday.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-11-03 18:18
    Unfortuntely, the change in baud did not make it work. Nothing happens except an LED blinks on the BASIC Stamp and on the TReX Jr, so I know it's receiving something, it's just not working. Here is my code, does anyone see anything wrong?:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    x VAR Byte
    y VAR Byte
    z VAR Byte
    DO
      DEBUG CR
      SEROUT 0, 84, [noparse][[/noparse]z, x]
      SERIN 16, 16468, Continue, 2000, Time_Out, [noparse][[/noparse]y]
    
    Continue:
      IF (y=97) THEN
      z=$C6
      x=127
      ELSEIF (y=115) THEN
      z=$C5
      x=127
      ENDIF
    
    Time_Out:
      x=0
    
    LOOP
    
    
  • Mike GreenMike Green Posts: 23,101
    edited 2008-11-03 18:27
    Sure ...

    The last thing done in the loop is to set x to zero. It's always done.

    Why do you have a parity error label when you've specified no parity? Read the SERIN description again.

    At a minimum, you need to put a GOTO after the ENDIF that goes to just before the LOOP

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    x VAR Byte
    y VAR Byte
    z VAR Byte
    DO
      DEBUG CR
      SEROUT 0, 84, [noparse][[/noparse]z, x]
      SERIN 16, 16468, 2000, Time_Out, [noparse][[/noparse]y]
      IF (y=97) THEN
      z=$C6
      x=127
      ELSEIF (y=115) THEN
      z=$C5
      x=127
      ENDIF
      GOTO Continue
    Time_Out:
      x=0
    Continue:
    LOOP
    
  • CorbettROVCorbettROV Posts: 17
    edited 2008-11-03 21:38
    Well even if it times out I want it to go into the loop; would that make it stop? I have edited it a little, I'll post it in a while.
  • CorbettROVCorbettROV Posts: 17
    edited 2008-11-03 23:01
    Here is my program:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    x VAR Byte
    y VAR Byte
    z VAR Byte
    DO
      DEBUG CR
      SEROUT 0, 84, [noparse][[/noparse]z, x]
      SERIN 16, 16468, Continue, 10000, Time_Out, [noparse][[/noparse]y]
    LOOP
    Continue:
      IF (y=97) THEN
      z=$C6
      x=127
      ELSEIF (y=115) THEN
      z=$C5
      x=127
      ENDIF
    
    Time_Out:
      z=$C4
      x=0
    
    



    I want it to go to "Continue" if it gets a y value and if it times out, i\I want it to go to "Time_Out". It's not working though.

    Thanks
Sign In or Register to comment.