Question about variable as input
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
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
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.
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
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