Skip to main content
Arduino

Return to Answer

Fixed typo in code: "(" → ", "
Source Link
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)));
}

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
  • 15
  • 29

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)));
}
default

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