I'm looking for help as I've spent far too long on a simple button problem in NR and clearly my head is now fogging up.
Here's the scenario - 2 buttons (on ESPs, grounded to operate - ESPs handle debouncing).
Status of the two buttons (0=pressed) comes into 2 similar functions in NR. All globals are initialised on NR power up.
Here's the function for button A (DOWN button) - both get "0" if button is pressed, "1" if released...
if (msg.payload=="1")
{
global.set("buttonA","released");
if (global.get("buttonB")=="pressed") { global.set("aWasPressed",0); msg.payload="a"; return(msg); }
else { if (global.get("bWasPressed")===0) { msg.payload="d"; global.set("aWasPressed",0); return(msg); } }
}
else { global.set("buttonA","pressed"); global.set("aWasPressed", 1); }
and button B (UP button) function (almost identical)
if (msg.payload=="1")
{
global.set("buttonB","released");
if (global.get("buttonA")=="pressed") { msg.payload="a"; global.set("bWasPressed",0); return(msg); }
else { if (global.get("aWasPressed")===0) { msg.payload="u"; global.set("bWasPressed",0); return(msg); } }
}
else { global.set("buttonB","pressed"); global.set("bWasPressed",1); }
The buttons work a treat, returning 'd' and 'u' when pressed. If both are pressed at once, on releasing the first one I get 'a' for auto.. That should be the end of it, as "aWasPressed" and "bWasPressed" are there to trap the second release - but this doesnt work and the second button release returns it's normal 'd' for down or 'u' for up even after an 'a' for auto
I'm obviously missing something. Once cracked I'll blog it so all can share - right now I'm at my wits end. HELP.