Page 1 of 1

Double click query

Posted: Mon Nov 30, 2020 1:10 pm
by ChrisT66
Hi, I am looking for a solution to the following problem: I want to query two states with one button. With a single click the first reaction occurs and with a double click the second one. The running program must not be blocked by the button query.
And the button is actually a switch that has any state at startup (0 or 1).

Does anyone have an idea?

Thanks a lot! Greeting Chris

Re: Double click query

Posted: Mon Nov 30, 2020 2:42 pm
by Benj
Hi Chris,

I would use a timer interrupt and maybe an edge driven interrupt.

The edge driven interrupt would monitor the switch input and determine when the switch was pressed.

The timer interrupt would monitor the passing of time.

Assuming the interrupt fires on each switch state change, If the switch changes state once or twice within a certain amount of time then do task 1, if the switch changes state three or four times within the time period then do task 2, otherwise do no task. The time period should probably reset on the first state change to allow you proper time to do the double click.

Here's a simple example.
DoubleClick.fcfx
(12.86 KiB) Downloaded 135 times

Re: Double click query

Posted: Mon Nov 30, 2020 3:40 pm
by ChrisT66
Hello, Ben,

thank you very much for the fast help!

Great that you have created an example for me.

Greetings Chris

Re: Double click query

Posted: Mon Dec 07, 2020 2:09 pm
by ChrisT66
Hi Ben,

i have tested your code and it works great for switches as needed! Thanks.
Now I wanted to implement the whole thing for changing signal widths. i.e. as soon as the signal width changes once LED 1 goes on, if it changes twice in a short time (double click) LED 2 goes on.
I used the pulse width measurement you once wrote me. I have only one problem: the double click does not work at the beginning, it must have been LED1 on first for the double click to work. A double click to start also switches only LED1 on and not LED2.
I can't find the error, I have inserted the code here... Maybe you or someone can help. Thanks a lot!

Re: Double click query

Posted: Thu Dec 10, 2020 11:25 am
by ChrisT66
Problem solved! Due to too long timer intervals....

Re: Double click query

Posted: Thu Dec 10, 2020 1:21 pm
by Benj
Excellent, thanks for letting us know and well done :D