I have a very simple test sketch in which I\'m trying to set a pin to HIGH and then read its state with digitalRead. Here is my sketch.
HIGH
digitalRead
<
Keep a separate boolean map of the output pin states.
If a microcontroller GPIO pin is set as an input, then its value, when read, depends on what it's connected to externally. That's kind of the point.