Page 1 of 1

Press 2 buttons at the same time

Posted: Wed Nov 29, 2017 12:26 pm
by Jan Lichtenbelt
Probably this questions has been raised before, but I could not find the answer.

How do you test that 2 buttens are pressed at the same time. In practice, on short time scale, one button will be pressed before the other. Thus just a simple interrupt on change will not work.

Who can help me?

Kind regards

Jan Lichtenbelt

Re: Press 2 buttons at the same time

Posted: Wed Nov 29, 2017 12:39 pm
by LeighM
On detect of either input, you could loop a fixed number of times, with a short delay in the loop, and count how many times each input is active. Outside the loop compare each count with a threshold value and make a decision as to whether you consider either or both pressed.
Although it assumes you have the time available to sit in the loop.
Hope that helps,
Leigh

Re: Press 2 buttons at the same time

Posted: Wed Nov 29, 2017 6:52 pm
by Steve001
Hi Jan

How about for example looking at port D and look at the entire port

button A on D4 button B on D5

button A would return 8 if the port was scanned button B would return 16

If button A & B where to be pressed then the port scan would return 24 (8 + 16)

Then you can make a decision on what to do biased upon the returned value

Steve

Re: Press 2 buttons at the same time

Posted: Wed Nov 29, 2017 9:01 pm
by Jan Lichtenbelt
This (equivalent) flowcode works fine. I used first a delay of 10 msec, but that was to fast. Now the delay is 100 msec between testing the status of the buttons.
The same can be done by means of IOC instead of a while statement.

Kind regards

Jan
Test_2_buttons_pressed.fcfx
(9.34 KiB) Downloaded 336 times