I suspect that this topic has arisen before !! (Apologises in advance !!)
I'd like to multi-purpose the pins in my current Arduino project. In essence, can I define a pin TWICE and safely use that definition within it's own "enviroment"
int pinPP_nAddrTag = 12; // Parallel port nAddrTag
int pinLED = 12; // The output LED pin (Also pinPP_nAddrTag)
Question 1 :
Is the attribute of INPUT specified in pinMode associated with the variable pinPP_nAddrTag or with pin 12 ??
As it says it is 'pinMode'; it acts on the pin. In your example code you set Pin 12 to INPUT and then you set it to OUTPUT. Therefore it is no longer an input. You need to be careful what you are doing here as you could damage the pin. Let's say you thought it was an input and set it high; that would turn the pullup resistor on, and you'd be expecting something to pull that pin low, with perhaps a direct short to Ground, against the pullup. If you did that when actually your pin was an output then you could short the pin to ground, exceeding it's current rating and destroy it.
Another way of looking at this is as follows ....
In function 1:
In function 2:
iDataRead = digitalRead(pinPP_nAddrTag);
Should I use pinMode(....) in the above functions to establish whether INPUT or OUTPUT) ?
It doesn't matter, you can't use it in both modes simultaneously. If you use it as an output first in Function1 then as soon as you set it to an INPUT it will go high impedance and your LED will light only dimly.
OUTPUT is a Low Impedance state
INPUT is a High Impedance state
Hopefully, you will be understand what I DON'T understand (or what I need reassurance on !!!)
Thanks in advance !
If you were just using it to send a signal then you could manage it's state and use it for both input and output consecutively. That's exactly how something like the I2C bus works but, you can't keep an output high and driven if you're going to change to input. If you had some way of latching the signal out so it only needed a momentary high then you could do so and then re-use the pin.
It's safer just to use one pin for one thing unless you fully understand the limitations.