Writing IF statement checking if Pin 6 is high

Hello,

I'm having trouble trying to synchronize pins 5&6 with an if statement. I would like for Pin 5 to go high&low when pin 6 does, but I'm having difficulty finding a solution for the syntax.

This is what I have so far.

void setup() {
// put your setup code here, to run once:
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(6, HIGH);
delay(3000);

digitalWrite(6, LOW);
delay(1000);

if ((digitalRead(6)) == HIGH)
{
digitalWrite(5, HIGH);
}
else (digitalWrite(5,LOW));
}

Thanks in advance

  if ((digitalRead(6)) == HIGH)

When this statement is executed pin 6 will always be LOW because of the preceding statements

Why not simply set the pins to the same state at the same time as one another ?

  digitalWrite(6, LOW);
  digitalWrite(5, LOW);

Why bother checking?

  digitalWrite(5, digitalRead(6));

But make sure 6 is an INPUT

1 Like

But make sure 6 is an INPUT

You can read the state of an OUTPUT pin, but can you write successfully to an INPUT pin ?

Hard to guess what is required - I'm just checking out ideas.

kimibird47:
I would like for Pin 5 to go high&low when pin 6 does,

Whatever happens on pin 5 only happens after the one second delay. And, since when it gets to that point pin 6 is always LOW...

https://forum.arduino.cc/index.php?topic=484306.0

Using millis() for timing beginner’s guide