Shop OBEX P1 Docs P2 Docs Learn Events
what is Ins.LowBit — Parallax Forums

what is Ins.LowBit

yzcheyzche Posts: 35
edited 2004-08-12 20:10 in BASIC Stamp
following code is from IR buddy manual

If(Ins.LowBit(pin)=0)


what is Ins
what is LowBit
what does Ins.LowBit mean?
is 0 then only option?
·

Comments

  • AllanL5AllanL5 Posts: 12
    edited 2004-08-12 19:54
    "INS" is a built-in variable, that refers to ALL the pins on the stamp as inputs.
    (You have to have SET the pin as an input to actually read the signal on the
    ·pin, otherwise you'll read the signal the BS2 is putting out on the pin.)

    .LowBit (aka .BIT0) is the lowest pin on the INS variable -- aka IN0.

    So the line you're asking about reads the state of P0 as an Input,
    and checks to see if it is zero (ie ground, ie zero volts).· It could
    also be a 1 (ie +5 volts).
    ·
  • Tracy AllenTracy Allen Posts: 6,656
    edited 2004-08-12 20:03
    Ins is the name of the 16 bit input register, that holds the state of the 16 stamp input pins

    Ins.LowBit refers to the lowest bit of Ins, otherwise known as In0.

    The Stamp has several different ways to refer to the same bit. Another way is Ins.bit0. Another is InL.lowbit. Another is InA.bit0. These names are very systematic and are described in the manual and in the help file.

    Ins.Lowbit(0) is yet another way to refer to in0, but with an array index.

    Ins.LowBit(1) is the same as in1
    Ins.LowBit(2) is the same as in2
    etc

    You might ask why go to so much trouble? Precisely because it lets you use an array index (the variable or constant "pin" in the example). By the way, they could have written it as,

    IF in0(pin) = 0 THEN ...
    which is the same as
    IF (Ins.LowBit(pin) = 0) THEN

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2004-08-12 20:10
    And with PBASIC 2.5 the PIN defintion simplifies things. Instead of:

    IrbPin CON 0 
    . 
    . 
      IF (INS.LOWBIT(IrbPin) = 0) ...
    



    we can do this:

    IrbPin PIN 0 
    . 
    . 
      IF (IrbPin = 0) ....
    



    Because the version 2.1 compiler can resolve the PIN definition to the INS variable for us.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
    Dallas Office
Sign In or Register to comment.