2542Views6Replies

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?

6 Replies

user
Hedayat.sa (author)2016-03-30

pinMode(14, INPUT);

pinMode(14, OUTPUT);

Select as Best AnswerUndo Best Answer

user
spiffomatic64 (author)2013-05-07

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

Select as Best AnswerUndo Best Answer

user
dennex (author)spiffomatic642015-01-11

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

Select as Best AnswerUndo Best Answer

user
mpilchfamily (author)2013-05-07

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?

Select as Best AnswerUndo Best Answer

user
David97 (author)mpilchfamily2013-05-08

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.

Select as Best AnswerUndo Best Answer

user
The Skinnerz (author)2013-05-07

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?

Select as Best AnswerUndo Best Answer