I noticed that when I insert in an "if" or a "while" a condition that places two inequalities in "and" or "or" it doesn't give me any errors but then when I use arduino it doesn't work! to give an example of what I mean: while (variable != x || variable != y) {
it doens't work
}
or even: if (variable != a && variable != b){
it doesn't work too
}
would anyone be able to tell me why and how can I fix it? I would be infinitely grateful to him.
Does your code (which you didn't post so we can't see it, hint hint) include serial prints to show what the values of the variables and the x's and y's etc actually are, and to show where the logic flow took you?
Read the sticky post at the top of every section which tells you how to get the most out of this forum. It will advise on things such as naming your query appropriately and how to post your code as well as how to ask an intelligible question. When you do that you are far more likely to get help.
actually yes, but even trying to disable them with // in front it doesn't work anyway
Well we will have to take your word for that, since you aren't sharing the code with us.
Why not just post the whole code in code tags?
I like to use one of these ( and one of these ) to separate out the logic sections such as
Serial.print ( "variable " );
Serial.print( variable );
Serial.print( " ! = a " );
Serial.print( !=a );
////I'm sure you can figure out how to print the rest, right?
Serial.println();
if ( (variable != a) && (variable != b) )
Okay wait, i didnt copy the right code, just read this one:
if(ris.value==SU){
//SA_fotoresistore=analogRead(A0);
while(ris.value!=STOP||ris.value!=GIU){
//SA_fotoresistore=analogRead(A0);
//Serial.println(SA_fotoresistore);
if(ricevitore.decode(&ris)){
ricevitore.resume();
//delay(100);
}
float gradi=5;
gradi=map(gradi,0,360,0,stepxgiro);
stepper1.step(-gradi);
contagradi=contagradi-5;
}
}
If you read how to use this forum you will discover you can edit a post. It’s a pencil here ¥
okay..
How can ris.value == and != SU at the same time? You do nothing to change ris.value between the if() and the while(), so when it's ==SU and the if() is successful, the while() cannot be a success.
That's exactly why I asked about serial prints to a) show all important values and b) show where the logic flow goes
i forgot to change the second SU with GIU for the rush
I mean that it doenst work with GIU too
Actually this doen't work
If you want folk to carry on trying to help... make sure you have the version you want members to check, add serial prints to show values and flow... then post it.
(By show the flow, I mean print messages like "we're in the first if" or "we're in the else part of the 3rd if" kind of thing.)
the right version is like its edited
now.. sorry for the mistakes made earlier by haste
The variable is a IR signal, if I put a print of that it would simply show a code, but the condition dont work
I'm out
i made a lot of mistakes because of the haste .. i think i will do another session when i explain everything clearly and unhurriedly .. thanks to everyone who tried to help me
Just start by reading how to use the forum. If you look at lots of other posts on here you will see your “haste” is more the norm than the exception.
Don't fire up a new thread, instead post a new item at the end of this one, with your improved explanation.
C