Shop OBEX P1 Docs P2 Docs Learn Events
IF ELS and Labels — Parallax Forums

IF ELS and Labels

earthlingzedearthlingzed Posts: 14
edited 2005-01-21 18:39 in BASIC Stamp
I am a newby getting myself acqquainted with the BS2, but I ahve a bit of programming expereince.

I am trying to create a simple if else statement and I keep getting error 148 asking for a label.
What is a label? It is not something I have run across in any other programming language.

Here is what I am trying to do:

' {$STAMP BS2}
' {$PBASIC 2.0}

INPUT 6
OUTPUT 7

Main:
LOW 7

  IF (IN6 = 1) THEN
    HIGH 7
  Else
    LOW 7
  END

GOTO main

Comments

  • NewzedNewzed Posts: 2,503
    edited 2005-01-21 16:08
    When you write an If..then, it must end with "endif", not end.

    The exception to this is if you write:

    if in0 =0 then high 5

    With a one-line command you do not need the endif.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Sid Weaver
    Do you have a Stamp Tester?

    http://hometown.aol.com/newzed/index.html
    ·
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-01-21 16:36
    First: You MUST use 2.5 syntax to get IF-THEN-ELSE.· In PBASIC 2.0 (which you have selected) you can only use the IF-THEN-Address version.
    Second: PBASIC 2.5 lets you define an IO pin as a PIN, and can simplify syntax.· Thus, your example becomes:

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
     
    Ctrl    PIN    6
    Led     PIN    7
     
    Reset:
      LOW Led                    ' make output and off
    
    Main:
      Led = Ctrl
      GOTO Main
    


    The key is that the compiler knows that your pins are pins and coverts

    Led = Ctrl

    to:

    OUT7 = IN6

    You next logical question is: What if I want to change to an active-low input?· No problem· Change the line to:

    Led = ~Ctrl

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas, TX· USA
  • earthlingzedearthlingzed Posts: 14
    edited 2005-01-21 18:39
    Thanks for the help. Once I switched to version 2.5 I had no trouble getting my simple application to work.

    Many thanks!
Sign In or Register to comment.