Arduino Forum

Forum 2005-2010 (read only) => Software => Syntax & Programs => Topic started by: arduiYES on Jan 18, 2011, 10:46 pm

Title: Changing Digital Pin from Read to Write in Routine
Post by: arduiYES on Jan 18, 2011, 10:46 pm
How does one change a Digital Pin from Read to Write in the program loop.  Is this simply a matter of redefining the pin.  Can these states be flexible due to incoming parameters and data?
For example...would it be possible to write a Digital Pin state conditional to a sensor reading....if sensorA is high then digitalpin2 Read sensorB....if sensorA is low then digitalpin2 Write High.
i know the syntax is quite wrong here...but i`m curious to know if it is a common thing that can be done....the same pin changing state mid routine based on other variables.  Can someone steer me in the right direction as to the "how" it can be done if possible?  thanks, arduiYES
Title: Re: Changing Digital Pin from Read to Write in Routine
Post by: PaulS on Jan 18, 2011, 11:07 pm
The mode of a pin (read/write) can be changed using pinMode(), in loop(). The pinMode command is not limited to use in setup().

The mode of the pin is changed frequently for the ultrasonic sensors. Set the mode to output to generate the pulse, then set it back to input to read the echoed pulse.
Title: Re: Changing Digital Pin from Read to Write in Routine
Post by: arduiYES on Jan 19, 2011, 12:29 am
that sure is super news PaulS.  much thanks