3025Views7Replies

Author Options:

Can a arduino pin mode be changed mid program? Answered

Hi, I'm working on a project that requires a reading to be taken from a pin (digital) and then that pin needs to be supplying power. Can I change the pinmode from input to output mid program, or do I need transistors to switch it between different pins instead?

Discussions

0
None
The blendera

5 months ago

I'm trying to use the 4 digit 7 segment display ad i cant seem to turn an ground on and off.

void setup() {

// put your setup code here, to run once:

}

void loop() {

digitalWrite(4, HIGH);

pinMode(11, INPUT);

digitalWrite(11, HIGH);

delay(500);

pinMode(11, OUTPUT);

digitalWrite(11, HIGH);

}

0
None
Hedayat.sa

2 years ago

pinMode(14, INPUT);

pinMode(14, OUTPUT);

0
None
spiffomatic64

5 years ago

Of course it can, look at the example->sensors->ping sketch :)

0
None
dennexspiffomatic64

Answer 3 years ago

How fast can this be achieved? would it take 1ms or less, or are we talking 100ms?

0
None
mpilchfamily

5 years ago

Will the output damage the device your reading from? Are you at a point where your out of available pins so one has to run double duties?

0
None
David97mpilchfamily

Answer 5 years ago

No I have a sensor that when a ball bearing falls over certain pins it can tell the direction. However there is a point that it can fall across 2 input lines which means that no reading would be taken. So I thought the easiest way to fix it would be to if there was no power supplied to that pin, it would power it to see what other ones the ball had fallen across.

0
None
The Skinnerz

5 years ago

As long as the external circuits connected to the pins don't interfere with each other, you can change any of the settings at any point in the program. Do you have a circuit for what you are trying to do?