hey guys,
is it possible to configure a pin as input and as output at the same time?
how ? pinMode(pin, OUTPUT/ INPUT) or something like that ?
hey guys,
is it possible to configure a pin as input and as output at the same time?
how ? pinMode(pin, OUTPUT/ INPUT) or something like that ?
What exactly are you trying to accomplish?
is it possible to configure a pin as input and as output at the same time?
Quite simply no.
If you think about it it doesn't make sense something that can sense what it is connecting to it and at the same time driving that something to a specified voltage.
You can switch between input & output any time, as many times as you want, but you can't read & write from one pin at the same time.
Typically, you'd need to switch your other hardware too, since an output from one device normally connects to the input of another device, and vice/versa. You speak out of your mouth (output) into someone's ear (input), and they speak out of their mouth (output) into your ear (input).
There's almost never a reason to read an output, since you (or your program/sketch) always knows the state of an output. However, you can connect an input pin to a different output pin to read the output-state.
Guys here is what I'm trying to do
have several arduinos connected, let's say pin9 of ard_1 is connected to pin8 of ard_2
arduino_1 send a signal to arduino_2 (pin9 to pin8)
then the arduino_2 will perfom some task
when finish, it says to arduino_1 that it finished (but using the pin8 connected to pin9 of ard_2)
so that the arduino1 can send another signal to other different arduino
that's it, I wanna send a signal from ard_1 to ard_2 and then send a signal from ard_2 to ard_1 using the same pins
What you are trying to do, but it needs a protocol (fixed procedure) to have a chance of working. Further, YOU MUST include 1k-10k of resistance between the two pins. If you don't and you accidentally try to write to both pins at the same time (one high, one low) you risk blowing both chips...
Something like I2C would achieve that.
In this situation both pins are usually set 99% of the time to input. Both ends are listening at the same time.
When a message wants to be sent, one end switches it's pin to output, and sends the message, then switches back to input to listen again.
You will have to provide a "default" state for the line for when both pins are listening, in the form of a pull-up or pull-down resistor on the line. That way, when there is no pin set as output the resistor will pull the voltage either towards +5v or down towards ground, giving the pins something to listen to.