Shop OBEX P1 Docs P2 Docs Learn Events
Help with BS1 code — Parallax Forums

Help with BS1 code

GradyTXGradyTX Posts: 3
edited 2013-09-25 22:21 in BASIC Stamp
Hi everyone,

I have a problem with some code, and I dont understand how to fix it. I have tried to digest as much as I can from the pdf manual, but
I am still confused. I have a BS1-IC, and the editor. I am able to load code just fine.

My board has the BS1-IC and four relays, which are each driven by a 2N3904 because they suck too much current. My circuit essentially
is like this: http://www.k8dav.com/U100_1/Circuit.jpg

What I desire to do is simply open a terminal window and send simple text to the BS1. For example, I type "R1" and then press enter.
Only relay-1 will come on, then go off, and so on for sending "R2" or "R3" or "R4".

The problem is I can type "R2", "R3" or "R4" and relay-1 will latch. I can even type just an "R" or type "R54321" still relay-1 will latch.
It works fine with simple blink code loaded, each relay behaves as coded, so I know the problem is my code. I've tried to get a better
understanding of this but I am a little discouraged now.


My BS1 code: Yes I dont know much about what I am trying to do...

' {$STAMP BS1}
' {$PBASIC 1.0}


SYMBOL relay = B3


DIRS=11111111
loop:
SERIN 0,N2400,("R"),relay
IF relay = 1 THEN ry1
IF relay = 2 THEN ry2
IF relay = 3 THEN ry3
IF relay = 4 THEN ry4


ry1:
HIGH 1
PAUSE 1000
LOW 1
GOTO loop


ry2:
HIGH 2
PAUSE 1000
LOW 2
GOTO loop


ry3:
HIGH 3
PAUSE 1000
LOW 3
GOTO loop


ry4:
HIGH 4
PAUSE 1000
LOW 4
GOTO loop


I hope I explained that alright. Any help would be greatly appreciated!

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2013-09-21 21:07
    Two problems ...

    1) You're waiting for the "R", then receiving the next character as a character, but testing for it as if it's a number. Easiest fix is to use "1" instead of 1, "2" instead of 2, etc.

    2) If the relay number doesn't match 1,2,3, or 4, your code just falls through to the ry1 case. Put a GOTO loop after the last IF statement.
  • GradyTXGradyTX Posts: 3
    edited 2013-09-25 22:21
    Hi Mike,

    Thanks a lot for the help! :smile:
Sign In or Register to comment.