Please tell if the while loop is correct, because I don't think so as it does not work. It just prints 0's and if it is wrong please supply me with a correct one.
while (! irrecv.decode( &results ) ) ; // Do nothing until there is a successful decode
val = results.value;
Let's hope the first signal you successfully decode is the one you were waiting for.
If you wanted to wait for a PARTICULAR signal:
boolean resume()
{
irrecv.resume();
return false;
)
.
.
.
// Do nothing until there is a successful and matching decode
while ( (!irrecv.decode( &results )) && (results.value == 33441975 || resume())) ;
The trick here is boolean shortcutting. If the left side of an "AND" is false, the right side is not evaluated. If the left side of an 'OR' is true, the right side isn't evaluated. This allows the irrecv.resume() to be called if a message has been received and decoded but the value is not correct
Thank you all! @johnwasser it now prints power off first but after about 500 milliseconds it prints power on without pressing the button on the IR remote...Please help!
TheUNOGuy:
Please explain more clearly. Thank you!
Really?
All your code is in the function setup.
Once setup finishes,the Arduino executes function loop forever until powered off.
You have nothing in loop.
So after it prints “power on”, that’s all folks...
If you could see the Arduion’s main function it would look something like this...
TheUNOGuy:
Thank you all! @johnwasser it now prints power off first but after about 500 milliseconds it prints power on without pressing the button on the IR remote...Please help!
Sounds like there is a mistake in your sketch. If you want further help you should post your latest sketch.