Skip to main content
Fixed typo in code: "(" → ", "
Source Link
Edgar Bonet
  • 45.2k
  • 4
  • 42
  • 81

Draw a truth table and look at it from there. From your words, it is confusing. From your code it looks like this:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     HIGH 

So:

void loop() {
      digitalWrite(relayPin(, !digitalRead(mainPin));
}

If you want:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     LOW 

then:

void loop() {
      digitalWrite(relayPin(, !(digitalRead(mainPin) || digitalRead(reedPin)));
}

Draw a truth table and look at it from there. From your words, it is confusing. From your code it looks like this:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     HIGH 

So:

void loop() {
      digitalWrite(relayPin(!digitalRead(mainPin));
}

If you want:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     LOW 

then:

void loop() {
      digitalWrite(relayPin(!(digitalRead(mainPin) || digitalRead(reedPin)));
}

Draw a truth table and look at it from there. From your words, it is confusing. From your code it looks like this:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     HIGH 

So:

void loop() {
      digitalWrite(relayPin, !digitalRead(mainPin));
}

If you want:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     LOW 

then:

void loop() {
      digitalWrite(relayPin, !(digitalRead(mainPin) || digitalRead(reedPin)));
}
Source Link
Dave X
  • 2.4k
  • 16
  • 30

Draw a truth table and look at it from there. From your words, it is confusing. From your code it looks like this:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     HIGH 

So:

void loop() {
      digitalWrite(relayPin(!digitalRead(mainPin));
}

If you want:

mainPin    reedPin   relayPin
HIGH        LOW      LOW
HIGH        HIGH     LOW
LOW         LOW      HIGH
LOW         HIGH     LOW 

then:

void loop() {
      digitalWrite(relayPin(!(digitalRead(mainPin) || digitalRead(reedPin)));
}