Setting outputs and read them

Hello,

I am trying to do a simple check - setting an output and read it's state, but something is wrong in my code.
I have 2 output pins, changing their state and reading it, but the problem is that I am always read high for both of them. :confused:
I would like to toggle the outputs and read them constantly, could you please point out my mistake?

Here is my code:

const int pinOut1 = 5;
const int pinOut2 = 6;
const int read1 = 3;
const int read2 = 4;

// state of the outputs
int out1State;
int out2State;

void setup() {
// serial comm at 9600bps
Serial.begin(9600);

// pin config
pinMode(pinOut1, OUTPUT);
pinMode(pinOut2, OUTPUT);
pinMode(read1, INPUT);
pinMode(read2, INPUT);
}

void loop() {

out1State = digitalRead(read1);
out2State = digitalRead(read2);

// ptint the outputs state in the console
Serial.print("\nOut 1 = ");
Serial.print(out1State);
Serial.print("\n Out 2 = ");
Serial.print(out2State);

digitalWrite(pinOut1, HIGH);
digitalWrite(pinOut2, LOW);
delay(500);
Serial.print("\nOut 1 = ");
Serial.print(out1State);
Serial.print("\n Out 2 = ");
Serial.print(out2State);
delay(500);

digitalWrite(pinOut1, HIGH);
digitalWrite(pinOut2, LOW);
delay(500);
Serial.print("\nOut 1 = ");
Serial.print(out1State);
Serial.print("\n Out 2 = ");
Serial.print(out2State);
delay(500);

digitalWrite(pinOut1, HIGH);
digitalWrite(pinOut2, HIGH);
delay(500);
Serial.print("\nOut 1 = ");
Serial.print(out1State);
Serial.print("\n Out 2 = ");
Serial.print(out2State);
delay(500);
}

and here is the console output:

Out 1 = 0
Out 2 = 0
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1
Out 1 = 1
Out 2 = 1

(deleted)

Well you're reading pins 3 and 4 and you're writing to pins 5 and 6 but you haven't said what is connected to any of them.

You wouldn't normally expect that writing to a pin is going to change the state of a completely different pin so I have no real idea what you're trying to do.

Steve

Pins 5 and 6 are connected to pins 3 and 4.
@spycatcher2k - you were right, this was exactly the issue. Thanks a lot!

Now I read the correct values, but I am wondering if I can perform a read and print constantly regardless of what and how I am changing in the outputs... For example read the two inputs at every 100ms and print the results, but changing the state of the outpus less frequently, e.g. 1 second or so.
I can't figure it out, could you please share some ideas?

As you are setting the state of the outputs you know what the state is so why do you need to read them ?