
JB2020 (Customer) asked a question.
"Double-Press" Button/Input
Does anyone have any easy ways to program a double-press for a button?
Detecting whether a button has been pressed once or "double-clicked" (for lack of a better term).
Is there any super easy ways to do this or is this just done with timers and counters?
I am using buttons to increase or decrease amplitude on a vibratory conveyor.
I would like to increment/decrement the amplitude by 1 using 1 press, or increment it by 5 using a double-press.
I also may add in a "hold button press", to return to 0 option.
Any thoughts are much appreciated! Thank You!
I've done similar things with timers and counters. That's probably the only realistic way to do it besides add another button exclusively for separating the functions. That is, unless someone else has a unique way to do it. I have one system that uses one push button. It starts 3 different cycles and also stops the system and resets anything within those cycles. I used a counter that keeps track of the button presses. After 2 seconds a timer will reset the button press count back to zero, or in your case, after x amount of seconds it will decide if it was one press or two and then either add 1 or 5 to your incremental value and reset the push button count. I'm assuming you're using a plc for this. It would be a pain to try and do any other way.
How I would do it is like this:
Rung 1: NO button push rising edge input contact and the NO blocker bit contact that is set from output contact in rung 2, go to a math block that adds +4 to the vibration intensity and resets the blocker bit.
Rung 2: NO button push rising edge input contact and a NC blocker bit contact, go to math block to add +1 to the vibration intensity and a set bit that blocks off this rung from ever going true again while the blocker bit is active.
Rung 3: NO input contact of just the blocker bit set from rung 2, go to a simple timer of .3s
Rung 4: NO timer done bit is the input contact, go to reset the blocker bit.
This will let the button be very responsive to inputs, as it adds a +1 count right at the first press and adds the rest of the count to total a +5 addition with two presses as soon as you press it a second time, and the button is immediately available again to add more. Typical "double clicks" of a mouse or button have a default threshold of around .2-.3 seconds in computer operating systems, so the time allotted for a double press is roughly similar to what people are used to and should be responsive while also not having many, if any, false triggers. You can play around with the timing to fine tune the feel of a double press action. Add another set of rungs for a subtraction count to do the same thing for removing intensity.
If you wonder why rung 1 is a +4 and has a blocker bit already in it and rung 2 is the +1, that is because if you do them the other way around with the "+1 rung" first then when you press the button it will likely evaluate both rung 1 and 2 as true in the same scan and always add a total of +5 with each press due to how logic and bits are evaluated. By having the secondary push in an earlier rung it prevents the secondary press function from being activated on the first scan for the button press.
Additionally, you will want to add a rung with a comparative contact for your vibration intensity where if the tag is greater than the maximum intensity value, then copy the maximum intensity value to the tag. This prevents a double press that wants to add more than is supposed to be the maximum count to cap it off at the maximum. Do the same thing for the subtraction rungs where you check if you are already less than 0. Since the rungs only take action if over or under the min/max they will not continuously trigger each scan while sitting at a min/max value.
That's a very nice approach. Good ideas!
Another possibility, have the "increment" button energize a timer. If the timer acc. is "<" a value, say 5-sec, then increment by "1" every sec. If the timer acc. is ">/=" the value, 5-sec, then increment by "5" every sec. When the button is released, the timer acc. resets to "0". I'm guessing you will have another button to act as the "decrement" button? This may be slower, or faster, to increment than the "single/double click" method depending on the desired incremented value and the time you select to determine if it's a double click or single click. I don't really understand your "hold to 0" option".
@PouchesInc (Customer) @JDoggyDrums (Customer) @K Price (Customer) Thanks for the ideas! If there's anymore ideas, I'm listening...
This gives me somewhere to start playing around with it. Yes I am using a separate button for decrementing the value.
Also, Yes I am using a P2000 for this. I was planning to create a UDI with this logic in it, because I have 10 of these vibratory conveyors that need the same logic. (I am loving the UDIs, makes it so easy!!)
The "hold to 0" option would be something like, if you hold the decrement button longer than x amount of time, then copy a 0 into the amplitude tag, effectively turning the amplitude to 0 to "start over". For instance, if the amplitude is set to 90% and for whatever reason I need to drop it to 5%, instead of double pressing the button 8 times (16 presses), I can just hold it to reset to zero and then increment back up to 5%.
The reset to 0 is easy to do. Just have two rungs:
Rung 1: your input button NO contact bit, go to a simple timer of however many seconds you want your hold to reset value to be.
Rung 2: NO done bit from the reset timer, to go a copy data instruction that copies a 0 to your intensity tag.
This is self resetting, in that as soon as you let go the timer goes false so everything functions as normal, and if you press and hold but not for a long enough time before releasing the button functions as normal and only adds or subtracts 1 from the intensity as it was designed for a single press. You can have the input to the reset timer be either buttons using the same rung, just "or" the contacts as the input for the rung. Another idea would be to do this reset to 0 only for holding the subtraction button, and do a "reset to 100%" intensity if you hold down the add button.
I think I got it figured out! I ran the Productivity Suite Simulator on it and it all worked as intended.
Thank You for the ideas and help!
P.S. If anyone wants a copy of the program I wrote, message me privately.
Good to see you figuring it out. I did an experiment back in July 2025.
https://community.automationdirect.com/s/feed/0D5PE00000fDtmu0AC