Hi,
I have two push buttons and need to run some code if EITHER ONE or BOTH are pushed.
So, basically I need to know the correct syntax for doing this in an if statement.
I have something like this:
if (sensorValue1 and sensorValue2 == HIGH) {
//run this code}
else if (sensorValue1 or sensorValue2 == LOW {
//run this code}
I am aware this is incorrect syntax and just need someone to help me out with the correct syntax for this kind of condition.
Thanks in advance!
if (sensorValue1 and sensorValue2 == HIGH) {
//run this code}
else (sensorValue1 or sensorValue2 == LOW {
//run that code}
for last condition, only use else I think.
That doesn't work. I think that it's not Arduino syntax to have the 'and' and 'or' there to seperate the two conditions? Someone please aware me on the correct syntax.
Try this:
if ((a ^ b) || (a && b)) {
// do something
}
the ^ is an XOR, the || is OR, and the && is AND.
you can replace the 'and's in your code with && and the 'or's with ||. You will also need to have the == HIGH for both, like this:
if (sensorValue1 == HIGH && sensorValue2 == HIGH) {
//run this code}
else if (sensorValue1 == LOW || sensorValue2 == LOW {
//run this code}
There is not really such a thing as "Arduino syntax". Arduino programs (sketches) are written in C/C++. Required reading here: http://arduino.cc/en/Reference/HomePage
Yess!! Thank you so much. My code works now