Shop OBEX P1 Docs P2 Docs Learn Events
If then statment checking pin state — Parallax Forums

If then statment checking pin state

ArchiverArchiver Posts: 46,084
edited 2003-12-30 16:24 in General Discussion
Hi All
Been some cool and helpful topics on the board thanks!

I have what is possibly a simple question but not sure of the command for it.
I would like to write a IF THEN statement that relies on if a output pin or
group of output pins are high.

IE not in correct code but idea

CHECK:
IF PIN 3 IS HIGH AND X>5 AND X<8 THEN PROGRAMCONTINUE
GOTO PROGRAM

PROGRAMCONTINE:
XXXXXX

I have no more variables to use in this code as they are all taken up.
I don't want to wait for the pin to go high just check its state and then if it
is high and the other variables are correct go to PROGRAMCONTINUE or other name.
Also I don't want to change the state of the output pin either just check its
state.


Thanks
Rob

[noparse][[/noparse]Non-text portions of this message have been removed]

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2003-12-30 15:11
    This is very do-able.
    The BS2 2.0c PDF has a table on page 49
    of the default names of groups of pins.

    For your example:

    MyPin3 VAR IN3 ' Declare an ALIAS to 'IN3'
    ' Alias entries take NO internal ram.
    DIR3 = 0 ' Insure pin 3 is an Input (0)

    MAIN
    IF (MyPin3 = 1) AND (X > 5) AND (X < 8) THEN ProgramContinue
    GOTO Program

    ' Note PBasic uses 'left to right' evaluation,
    ' unless you use the parentheses to force
    ' the order.

    Note also that PBasic 2.5 allows you:
    MyPin3 VAR PIN
    Then you get more flexibility when using
    'MyPin3'. In 2.0, you must declare the
    alias as Input only, or Output only.

    --- In basicstamps@yahoogroups.com, "Rob Farrand ... FTech
    Connection" <ftech@n...> wrote:
    > Hi All
    > Been some cool and helpful topics on the board thanks!
    >
    > I have what is possibly a simple question but not sure of the
    command for it.
    > I would like to write a IF THEN statement that relies on if a
    output pin or group of output pins are high.
    >
    > IE not in correct code but idea
    >
    > CHECK:
    > IF PIN 3 IS HIGH AND X>5 AND X<8 THEN PROGRAMCONTINUE
    > GOTO PROGRAM
    >
    > PROGRAMCONTINE:
    > XXXXXX
    >
    > I have no more variables to use in this code as they are all taken
    up.
    > I don't want to wait for the pin to go high just check its state
    and then if it is high and the other variables are correct go to
    PROGRAMCONTINUE or other name.
    > Also I don't want to change the state of the output pin either just
    check its state.
    >
    >
    > Thanks
    > Rob
    >
    > [noparse][[/noparse]Non-text portions of this message have been removed]
  • ArchiverArchiver Posts: 46,084
    edited 2003-12-30 16:24
    Note that the correct syntax for declaring PINs is:


    ' {$PBASIC 2.5}

    MyPin3 PIN 3


    Using this syntax the compiler is able to intelligently determine how to
    use the pin, as there are times when we want to use a constant value
    (i.e., 3), monitor the input bit (i.e., IN3), or set the output bit
    (i.e., OUT3) for a given pin.

    Happy New Year!

    -- Jon Williams
    -- Applications Engineer, Parallax
    -- Dallas Office



    Original Message

    <snip>

    Note also that PBasic 2.5 allows you:
    MyPin3 VAR PIN

    </snip>
Sign In or Register to comment.