Greetings,
I wanted some button logic for two different output states:
(1) change and hold the state to ON/OFF on EACH button press
(2) changes on JUST ONE CYCLE to 'ON' on a button press
the code...
function myOnOffButton(swButtonAction)
{
// ON/OFF Button Logic- Terry Abbott - 2023.03.18
// single button flipflop logic
// changes and holds the state to ON/OFF on EACH button press
// (button should be set up as press/release)
if (root["SwFlipFlop"]==null)
{
root["SwFlipFlop"]=0;
}
if (root["SwOnOff"]==null)
{
root["SwOnOff"]=0;
}
if (swButtonAction != root["SwFlipFlop"])
{
if (root["SwFlipFlop"] == 0)
{
root["SwOnOff"] = !root["SwOnOff"];
}
root["SwFlipFlop"] = swButtonAction;
}
return root["SwOnOff"];
}
function myOneShotButton(swButtonAction)
{
// ONE-SHOT Button Logic- Terry Abbott - 2023.03.18
// single button flipflop logic
// changes on JUST ONE CYCLE to 'ON' on a button press
// (button should be set up as press/release)
var oneShot;
if (root["SwFlipFlop"]==null)
{
root["SwFlipFlop"]=0;
}
if (root["SwOnOff"]==null)
{
root["SwOnOff"]=0;
}
oneShot = false;
if (swButtonAction != root["SwFlipFlop"])
{
if (root["SwFlipFlop"] == 0)
{
// should really be set to true, with each call ic'd to false
oneShot = true;
}
root["SwFlipFlop"] = swButtonAction;
}
return oneShot;
}