Shop OBEX P1 Docs P2 Docs Learn Events
Need some help with BS2 syntax - IF...THEN — Parallax Forums

Need some help with BS2 syntax - IF...THEN

Otaku1031Otaku1031 Posts: 34
edited 2011-01-09 21:10 in BASIC Stamp
Hi all,
I'm having some difficulty with getting this sequence to work:
I'm using pin 12 as an input for a logic signal from a CD4070 gate. I need to look at this signal, determine if it's 0 or 1, and take the appropriate action. If the signal is 1 (indicating a test failure) I want to make pin 13 high to turn on an LED. Here's what the code looks like right now:

IF IN12 = 1 THEN OUT13 = 1
END IF

When I check syntax, I keep getting errror msg's like "Expected: Label". I've been using Excel VBA for > 10 years, but this is my first exposure to PBASIC. I can't seem to find a code example anywhere that shows how to turn a pin ON based on the input (high/low) to a different pin. I have pin 12 defined as an input and 13 defined as an output. Can anyone point me in the right direction? Many thanks!

Gary

Comments

  • W9GFOW9GFO Posts: 4,010
    edited 2011-01-07 17:24
    When your IF Statement is completed in one line you do not need the ENDIF.

    Also, ENDIF is one word.

    Rich H
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-01-07 18:15
    Thanks, Rich. I was able to get the Syntax Check to accept this:

    IF IN12 = 1 THEN Fail_LED
    END

    Fail_LED:
    HIGH 13
    END

    I may stick with this, as I'll need to reference Fail_LED several times in this program. I'll test your suggestion first thing when I get back to work. Thanks again!
  • W9GFOW9GFO Posts: 4,010
    edited 2011-01-07 19:43
    "END" belongs only at the end of the program. You do not need to "end" the IF statement if it takes only one line.

    This needs an ENDIF;
    IF a = 1 THEN
    b = a + 1
    GOSUB somethingElse
    PAUSE 10
    ENDIF
    

    This does not need an ENDIF;
    IF a = 1 THEN GOSUB somethingElse
    

    Rich H
  • Otaku1031Otaku1031 Posts: 34
    edited 2011-01-07 20:11
    Aha! Hey, thanks again. This will make things go faster.
  • ercoerco Posts: 20,256
    edited 2011-01-08 08:43
    If in12=1 then high 13
  • Tracy AllenTracy Allen Posts: 6,662
    edited 2011-01-08 09:43
    Or simply, assuming p13 has already been made an output,
    out13 = in12
    
  • ercoerco Posts: 20,256
    edited 2011-01-08 21:47
    @Tracy: Molto elegante!
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-01-09 21:10
    Yessir, that "END" command stops everything..... as in, the micro does absolutely nothing else unless you cycle power (reset) and force a program restart. So in the example you give, the program will perform the check and in either case (True/false) it stops execution. This may be exactly what you intended, but I imagine you'll need some kind of a branch function too, GOSUB or GOTO
Sign In or Register to comment.