Shop OBEX P1 Docs P2 Docs Learn Events
Can you set an alias for an input pin? — Parallax Forums

Can you set an alias for an input pin?

jason777jason777 Posts: 11
edited 2007-07-24 17:08 in BASIC Stamp
You can set a contant for an output like this:
RightServo· PIN 12

Can you do so for an input? Like:
IrDetectorLeft·· PIN IN7


This way you dont have to hardcode the number in your code like
FREQOUT 8, 1, 38500
irDetectLeft = IN7

Here, IN7 is hardcoded. I want to declare it at the top in case I changes its location.

Sorry for the noob question.

Comments

  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2007-07-23 23:11
    Input pins can be declared with the PIN statement, too:

    IrDetectLeft PIN 7
    ...
    Value = IrDetectLeft    'Read the pin.
    
    
    



    -Phil
  • allanlane5allanlane5 Posts: 3,815
    edited 2007-07-24 15:07
    Note the "PIN" statement is a "PBasic 2.5" keyword -- not a problem, just insure you've enabled PBasic 2.5 for your program.
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-07-24 17:08
    Here

    Here is an article on the PIN declaration, including possible special or ambiguous situations. It includes some correspondence with Jeff Martin about the compiler rules.

    You can also declare the aliases in the old (pre PBASIC 2.5) way:

    outPin CON 7 ' output references like HIGH outPin
    outBit VAR out7 ' output references like outBit=1
    inBit VAR in8 ' input references to inPin will use in8, x=inBit

    or new (PBASIC 2.5):

    myPin PIN 7 ' for either output or input, depending on context

    At compile time, each instance of myPin in the program is resolved to one of the "old" type of references, as appropriate in context. There is a set of rules that the compiler uses to make that decision.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
Sign In or Register to comment.