I've recently started Arduino and I am trying to get two push button inputs to turn on an LED but the only condition is that both of the push button have to be on for the LED to be on. thankyou for any feedback
No need to compare truth values against truth values when what's wanted in an 'if' is a truth value anyway. HIGH is true and LOW is false.
It is, on the other hand, actually necessary to call digitalRead() inside loop.
And, I completely disagree with you. Comparing the return code from digitalRead() to HIGH or LOW shows that you know what the function returns for the way you have the switches wired.
MarkT:
No need to compare truth values against truth values when what's wanted in an 'if' is a truth value anyway. HIGH is true and LOW is false.
That happens to be true, but the documentation doesn't specify that this is the case. If you rely on that, then you are relying on undocumented behaviour.
MarkT:
No need to compare truth values against truth values when what's wanted in an 'if' is a truth value anyway. HIGH is true and LOW is false.
I must say that when I am reading my own code I find the lengthier if(button1 == HIGH && button2 == HIGH) much easier to follow. I'm sure the compiler can optimize properly.