6v6gt:
You may have more success using millis() instead of delay() like in this example code (untested).
It will not, however, be compatible with any delays you have elsewhere in your code.unsigned long inMuteMs = 0 ;
. . .
. . .
void loop() {
. . .
. . .
//MUTE
if (results.value == 3772837903) {
//remote button MUTE
if ( millis() - inMuteMs > 1000 && inMuteMs != 0 ) {
// abandon old mute attempt
inMuteMs = 0 ;
}
else if ( millis() - inMuteMs > 500 && inMuteMs != 0 ) {
// valid mute
results.value = 0;
analogWrite(LED, LEDon ? LOW : volume); //Turn the LED on or off, depending on if ledOn is true or false
LEDon = LEDon ? false : true; //Toggle between false and true
inMuteMs = 0 ;
}
else if ( inMuteMs == 0) {
// start of new mute attempt
inMuteMs = millis() ;
}
}
. . .
. . .
}
Thanks, this may be the direction I need to take. I studied millis() earlier today but the Arduino page I looked at implied it was only for determining elapsed time. I'll see if I can dig deeper.
Meanwhile I tried your code. The good news is it ran first try. Buy it's not quite there. When I hold the Mute button down for an extended period of time, it flashes my Pin 9 LED every 500 mS. That would be acceptable except that it does not respond to a short tap of the Mute button Longer presses yield unpredictable results. So I find myself having to use short and long presses to toggle the LED on and off.
I'll dig into your code to see if I can understand how it works. I'm new to this and dyslexia doesn't help, especially when trying to keep track of toggle states.