Shop OBEX P1 Docs P2 Docs Learn Events
Question about variable as input — Parallax Forums

Question about variable as input

SSchafferSSchaffer Posts: 12
edited 2009-02-14 00:06 in BASIC Stamp
I have what should be a simple problem, but I have not been able to come up with a solution:

I want to make my Input a variable that is dependent upon the value of another variable.

What this means is that I have a variable called "reader", and I receive this value via a serial connection. If the value for reader is 1, then I want the Input to be Pin 6 and if the value is 2, then I want the Input to be Pin 10.

I know that if I declare Pin 6 to be an Input, then I write "Input 6" and then refer to the value as "IN6".

If I write "Input num" then do I refer to it as "INnum" when checking its value?

Thanks,
···· Scott

Comments

  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2009-02-13 19:34
    Hi Scott, you are right in your assumption of refering to the INnum , you might need some conditional code to associate the "reader" value with the input pin

    eg:

    Reader VAR Byte
    Result VAR Bit ' placeholder for the input value
    SELECT reader
    · CASE 1
    · result=IN6·· 'checking P6
    · CASE 2
    · result=IN10· 'checking·P10
    · CASE 12
    · result=IN0·· 'checking P0
    ENDSELECT

    Jeff T.
  • SSchafferSSchaffer Posts: 12
    edited 2009-02-13 20:51
    Hi,
    Thanks for your response! So I would do the following then:

    result = IN6
    IF (result = 1) THEN
    ...

    I don't need to declare "INPUT 6" because the Pin's default state is as an Input, right?

    Thank you for your help.

    Scott
  • JDJD Posts: 570
    edited 2009-02-14 00:06
    SSchaffer,

    Yes; When the BASIC Stamp is powered up, or reset, all memory locations are cleared to 0, so all pins are inputs (DIRS = %0000000000000000). Also, if the PBASIC program sets all the I/O pins to outputs (DIRS =%1111111111111111), then they will initially output low, since the output latch (OUTS) is cleared to all zeros upon power-up or reset, as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Joshua Donelson

    www.parallax.com
Sign In or Register to comment.