Press 2 buttons at the same time

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 7.

Moderator: Benj

Post Reply
User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Press 2 buttons at the same time

Post 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

User avatar
LeighM
Matrix Staff
Posts: 2178
Joined: Tue Jan 17, 2012 10:07 am
Has thanked: 481 times
Been thanked: 699 times

Re: Press 2 buttons at the same time

Post 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

Steve001
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed Dec 31, 2008 3:37 pm
Has thanked: 460 times
Been thanked: 523 times

Re: Press 2 buttons at the same time

Post 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
Success always occurs in private and failure in full view.

User avatar
Jan Lichtenbelt
Posts: 797
Joined: Tue Feb 17, 2009 8:35 pm
Location: Haren GN, the Netherlands
Has thanked: 128 times
Been thanked: 264 times
Contact:

Re: Press 2 buttons at the same time

Post 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 332 times

Post Reply