My question is why is that the case? What is the point of setting a pin to INPUT if OUTPUT can still read in values? Are there any disadvantages of doing so?
If you do a digitalRead
you can read the current latched state of an output pin (it doesn't change it to input). In other words, you read what was last written to it.
If you do a digitalWrite
of HIGH to an input pin it sets the internal pull-up. If you write LOW it disables the internal pull-up. If it switched it to output for you, you wouldn't be able to enable or disable the pull-up. (Note: this applies to older versions of the IDE, newer ones have a pinMode setting of INPUT_PULLUP).
What is the point of setting a pin to INPUT if OUTPUT can still read in values?
That certainly won't work with digitalRead
because you are writing a value to the pin in OUTPUT mode, so you will merely read back what you are writing. In other words, you have activated the driver transistors, which will override whatever value you are trying to read.