Skip to main content
Arduino

Return to Revisions

2 of 2
Fixed typo in code: "(" → ", "
Edgar Bonet
  • 45.1k
  • 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)));
}
Dave X
  • 2.4k
  • 15
  • 29

AltStyle によって変換されたページ (->オリジナル) /