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.
<
Your sketch should be
void setup()
{
Serial.begin(9600);
}
void loop()
{
delay(1000);
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
delay(1000);
// pinMode(3, INPUT); // get rid of this line
Serial.println(digitalRead(3));
}
That's all. Then it reads the pin's state which in your case is "HIGH". If you set the pinMode to input it will read the input depending on what is connected. If you are writing "HIGH" to an input pin the internal pullup will be activated. It does not matter if you write HIGH before setting it to input mode or after setting it to input mode. Unless of course you are driving a load that is to high for the output pin (e.g. a switch to ground). Then this would probably kill the pin.
If you have written a low and set the pin to low it might float which may lead to any kind of unpredictable behaviour.