Pages: [1]   Go Down
Author Topic: Changing Digital Pin from Read to Write in Routine  (Read 855 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 64
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50166
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 64
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

that sure is super news PaulS.  much thanks
Logged

Pages: [1]   Go Up
Jump to: