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