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
Double click query
Moderator: Benj
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Double click query
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Double click query
Hello, Ben,
thank you very much for the fast help!
Great that you have created an example for me.
Greetings Chris
thank you very much for the fast help!
Great that you have created an example for me.
Greetings Chris
Re: Double click query
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!
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!
- Attachments
-
- DoubleClick.fcfx
- (12.86 KiB) Downloaded 122 times
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Double click query
Excellent, thanks for letting us know and well done
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel