There are 3 booleans: a, b and c.
a and b are like buttons. They are normaly false. Only when triggered are true. Like an impulse.
When I triiger the a, the c should be true and should keep the sate untill the b is triggered. After triggering b, the c should go into false, keeping the state untill the a is triggered again.
I want to write it in JavaScript. I need it for hmi software to control the real buttons. Thanks.
You can use ternary operators (?:) and negation (!):
let A = false, B = false, C = false, a = document.getElementById('a'), b = document.getElementById('b'), c = document.getElementById('c');
function changeC(clickedBtn) {
if(clickedBtn === 'a') {
a.innerHTML = A === false ? true : false;
A = !A;
}
else if(clickedBtn === 'b') {
b.innerHTML = B === false ? true : false;
B = !B;
}
c.innerHTML = C === false ? true : false;
C = !C;
}
<button id="a" onclick="changeC('a')"> false </button>
<button id="b" onclick="changeC('b')"> false </button>
<button id="c"> false </button>