Go Down

Topic: What happens when I digitalRead() a pin that is in PWM output mode? (Read 1 time) previous topic - next topic


Hi there, I'm wondering what value would I get when I digitalRead() from a pin that is currently set to output in PWM mode (analogWrite)? Would I expect to read whatever value that is being driven by the PWM output, or would I get a fixed value?

Thanks much,
- K.


You will turn that output pin into an input pin, and your reading depends on what is connected to the pin.


have you a reference to confirm that?

I was thinking it would return the last value written to it... so it can return either a 1 or a 0  just depends....
NB digitalRead() does not call inputMode(...) ?

Note: there is some blinking led code like:  digitalWrite(LED, !digitalRead(LED));

just wondering...
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


I would tend to agree with Rob.  I certainly don't think that the data direction register would be changed (making the pin an input pin) since there are perfectly legitimate reasons to read from an output port and to write to an input port.


Coding Badly

I vaguely recall that the PWM module has its own pin driver.  If that's true, then digitalRead returns the last value written to the pin before PWM was enabled.

Go Up