Hello, I am looking for a good solution to count the clicks of a button/switch. I am evaluating the change of a pulse to its “normal value”. Attached is a routine that works great for a switch. I also have a routine for a button. Now I am looking for a routine that can do both, regardless of whether a button or switch is connected. Does anyone have any ideas?
Many thanks in advance!
Chris
Click counter
-
- Posts: 103
- http://meble-kuchenne.info.pl
- Joined: Mon Dec 07, 2020 12:47 pm
- Been thanked: 1 time
-
- Matrix Staff
- Posts: 1993
- Joined: Wed Dec 02, 2020 11:07 pm
- Has thanked: 630 times
- Been thanked: 665 times
Re: Click counter
Hi Chris the attached should only work for momentary switches, buttons etc.
It returns the port bit that triggered the IOC
As you have not got a switch connected to bit 0 then the true bit is returned.
If you did have a switch connected to bit 0, then the project can be changed so port bit +1 is returned
It can only detect one one switch pressed, it can't detected multiple switches.
If that was the case, the code will require changing.
I have not tested on hardware, but I will if you state it does not work.
It returns the port bit that triggered the IOC
As you have not got a switch connected to bit 0 then the true bit is returned.
If you did have a switch connected to bit 0, then the project can be changed so port bit +1 is returned
It can only detect one one switch pressed, it can't detected multiple switches.
If that was the case, the code will require changing.
I have not tested on hardware, but I will if you state it does not work.
- Attachments
-
- Testclick2.fcfx
- (29.6 KiB) Downloaded 117 times
Martin
Re: Click counter
Hello Martin,
thanks for your idea, works great.
But I haven't connected any buttons or switches to a port. I get the information whether the button or switch has been pressed via the change in the received pulse length. Let's say button/switch not pressed means pulse length short. Pressed then means long pulse length.
My problem is that with one switch the pulse goes from short to long and with the next press from long to short. The button, however, goes from short to long and then back to short with every click.
thanks for your idea, works great.
But I haven't connected any buttons or switches to a port. I get the information whether the button or switch has been pressed via the change in the received pulse length. Let's say button/switch not pressed means pulse length short. Pressed then means long pulse length.
My problem is that with one switch the pulse goes from short to long and with the next press from long to short. The button, however, goes from short to long and then back to short with every click.
-
- Valued Contributor
- Posts: 1607
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 357 times
- Been thanked: 565 times
Re: Click counter
Hi
Can you explain a bit more why you need to measure the length of a pulse to determine whether or not something has been "clicked", as it seems quite an overcomplicated way to count.
I appreciate that switches / buttons do not always actually represent such, they just mimic, but if we have a better understanding of what you need to do then maybe we can help better.
Regards
Can you explain a bit more why you need to measure the length of a pulse to determine whether or not something has been "clicked", as it seems quite an overcomplicated way to count.
I appreciate that switches / buttons do not always actually represent such, they just mimic, but if we have a better understanding of what you need to do then maybe we can help better.
Regards
Re: Click counter
Yes, of course I will.
The information as to whether the button/switch has been pressed and how many times in succession (up to 12 clicks) is transmitted via radio. I have to count on the receiver side (pulse width modulated signal). As soon as the pulse length changes, I know whether it has been pressed.
My aim now is to always count the number of clicks correctly, even if I don't know whether a button or switch is connected.
I think this is probably only possible if I measure the length of the pulses and if it is short enough, it should be a button.
The information as to whether the button/switch has been pressed and how many times in succession (up to 12 clicks) is transmitted via radio. I have to count on the receiver side (pulse width modulated signal). As soon as the pulse length changes, I know whether it has been pressed.
My aim now is to always count the number of clicks correctly, even if I don't know whether a button or switch is connected.
I think this is probably only possible if I measure the length of the pulses and if it is short enough, it should be a button.
Re: Click counter
With just one click, the pulse length of the switch does not return to the original value, but the push-button does.
With two clicks, for example, the length of the changed pulse width for the switch until it returns to the original value is normally just as long as two pulses from the button.
(The “switch” is physically a button that behaves like a switch).
With two clicks, for example, the length of the changed pulse width for the switch until it returns to the original value is normally just as long as two pulses from the button.
(The “switch” is physically a button that behaves like a switch).
- Attachments
-
- 2Clicks.jpg (61.95 KiB) Viewed 5030 times
-
- Valued Contributor
- Posts: 1607
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 357 times
- Been thanked: 565 times
Re: Click counter
Hi
That is helpful. If I understand correctly a short pulse equals a button press whilst a long pulse equals a switch?
Have you measured min/max time for each?
Regards
That is helpful. If I understand correctly a short pulse equals a button press whilst a long pulse equals a switch?
Have you measured min/max time for each?
Regards
Re: Click counter
If I start a counter when the signal changes, I count in a loop without delays with a button up to approx. 5 with an 8Mhz processor, a switch is above 10 counts
Regards
Regards
-
- Valued Contributor
- Posts: 1607
- Joined: Thu Dec 03, 2020 10:57 am
- Has thanked: 357 times
- Been thanked: 565 times
Re: Click counter
Hi
Thanks again. It should be relatively easy to measure the width of an incoming pulse and there are a few different options open to you.
However I think the issue will be in controlling the switch / button as by nature they do not open/close cleanly (bounce).
Stupid suggestion time. Would it be possible to employ a basic PIC (for example) to interface the button /switch? The PIC on detection of a button could pulse for a given time, a longer time for switch etc?
I assume the RF is a very basic setup, only providing CW?
Regards
Thanks again. It should be relatively easy to measure the width of an incoming pulse and there are a few different options open to you.
However I think the issue will be in controlling the switch / button as by nature they do not open/close cleanly (bounce).
Stupid suggestion time. Would it be possible to employ a basic PIC (for example) to interface the button /switch? The PIC on detection of a button could pulse for a given time, a longer time for switch etc?
I assume the RF is a very basic setup, only providing CW?
Regards
Re: Click counter
Hi, unfortunately I have to live with the signals as they are.
I have a test program where the detection between switch and button works quite well. If a push-button is detected, Mode is set to 1. The next click continues in the button click menu.
But now I have a completely different problem that is giving me even more gray hair than I already have.
At the beginning I let an LED flash once. If I now start the controller several times (power on/off), the LED flashes twice from time to time, which is not possible according to the program.
Another phenomenon is that when I am in the switch menu (Mode=0) and click frequently, it suddenly jumps to Mode=1, which is also normally impossible. Where can this come from? If I program a different program into the controller, everything works without errors.
I have a test program where the detection between switch and button works quite well. If a push-button is detected, Mode is set to 1. The next click continues in the button click menu.
But now I have a completely different problem that is giving me even more gray hair than I already have.
At the beginning I let an LED flash once. If I now start the controller several times (power on/off), the LED flashes twice from time to time, which is not possible according to the program.
Another phenomenon is that when I am in the switch menu (Mode=0) and click frequently, it suddenly jumps to Mode=1, which is also normally impossible. Where can this come from? If I program a different program into the controller, everything works without errors.
- Attachments
-
- Testclick.fcfx
- (36.21 KiB) Downloaded 113 times