Joes
August 13, 2014, 8:31pm
1
hi there I have this code what works fine
if ((FalSafeValue < 359 && (failFlag == false)) {
but I would like to add a diditalRead in this.I have had a go in the code below but now that piece of the code doesn't seem to work at all now.
if ((FalSafeValue < 359) ll !digitalRead(tempFalSafe) && (failFlag == false)) {
what have I done wrong?
system
August 13, 2014, 8:36pm
2
The logical OR operator is ||
Joes
August 13, 2014, 8:54pm
4
yes sorry it is ||
any other ideas?
My crystal ball says your problem is on line 28.
You need to do two things:
Elaborate. "It doesn't work" is not helpful. What do you expect to happen? What actually happens?
Post all of your code, along with a schematic of what's attached where.
Use more () to enforce the order of evaluation is probably part of the solution
if ( ( (FalSafeValue < 359) || !digitalRead(tempFalSafe)) && (failFlag == false) ) { // do the OR part first
differs from
if ( (FalSafeValue < 359) || (!digitalRead(tempFalSafe) && (failFlag == false) ) ) { // do the and part first
Robin2
August 14, 2014, 9:04am
7
Your code will probably be easier to follow if you read the value into a variable and then use the variable in the if statement
byte tempVal = ! digitalRead(tempFalSafe);
if ((FalSafeValue < 359) ll tempVal && (failFlag == false)) {
Those complex IF statements can be notoriously difficult to create. With 3 variables there are 8 possibilities - have you got the correct one? Should only one of the 8 be included - i.e. should the other 7 be definitely excluded?
If it was my code I would break them out at least into nested single statements. But I would prefer to use one (or two) of the tests to eliminate stuff completely to reduce the need for nesting.
...R