What’s the best way to do a dual input software flip flop? Can't wait around to do pulsin or handle interrupts. Input low must be detected as the program cycles through and polls the input pins, then toggles a bit.
Came up with this, it seems rather cumbersome. It depends on successive cycles through the software to capture the input change. It works since the input stays low long enough for it to be polled by several cycles.
if pin1 = 0 and bit0 = 1 then let bit1 = 1 'first input, capture low input
and set bit 1
bit0 = pin1 update bit 0
if pin2 = 0 and bit2 = 1 then let bit1 = 0 '2nd input, capture low input
and reset bit 1
bit2 = pin2 update bit 2
Is there a better way to do this without affecting the program loop time?
Came up with this, it seems rather cumbersome. It depends on successive cycles through the software to capture the input change. It works since the input stays low long enough for it to be polled by several cycles.
if pin1 = 0 and bit0 = 1 then let bit1 = 1 'first input, capture low input
and set bit 1
bit0 = pin1 update bit 0
if pin2 = 0 and bit2 = 1 then let bit1 = 0 '2nd input, capture low input
and reset bit 1
bit2 = pin2 update bit 2
Is there a better way to do this without affecting the program loop time?