Skip to content
If this is your first visit, please click here to learn about shipping and delivery.
If this is your first visit, please touch here to learn about shipping and delivery.
Small momentary push-buttons with coloured caps

One Small Button, Two Clear Actions: Short-Press and Long-Press Logic

A compact project may have room for only one button. A short press can select the next item, while a long press opens a settings mode. The difficult part is making those gestures unambiguous: a long press must not accidentally perform the short action first.

The PMD Way 8 mm buttons collection includes momentary buttons in several colours. Their small size can suit a compact control, provided the actual mounting dimensions, contact arrangement and ratings meet the design. This guide concentrates on interpreting one button deliberately, after its electrical input has been established.

Define the gestures in plain language

Write down the behaviour before choosing a timing constant. For a simple example, a released short press advances one menu item, while a hold past a chosen threshold enters settings once. Releasing after that long action performs no additional command.

Decide whether the long action happens when the threshold is crossed or only when the button is released. These are different interfaces. Acting at the threshold gives immediate feedback; acting on release allows the whole press duration to be classified before any command occurs.

Keep destructive or safety-related operations out of an ambiguous gesture. A long press alone is not an appropriate safety interlock. For an ordinary configuration change, a separate confirmation screen or explicit cancel path can make the consequence clearer.

Establish a clean input first

Identify the actual contact pair with the button disconnected from power. Confirm the released and pressed continuity states, then connect it to a suitable controller input using a defined bias arrangement. Check the input voltage limits and the switch's suitability for the intended low-current signal.

The linked product description does not provide a complete electrical rating or mounting drawing. Do not interpret “8 mm” as a guaranteed panel cut-out dimension, nor assign a mains or power-switching rating from appearance. Obtain the required details or measure a sample for the mechanical prototype.

Mechanical contacts can bounce. Use a debounce stage to produce stable pressed and released states before measuring the gesture. Microchip's debounce background explains why several raw transitions can result from one physical operation.

Use an explicit press lifecycle

A useful classifier has three states: ready, pressed and long action already sent. The last state prevents a held button from sending the long command on every pass through the program loop.

One possible threshold-triggered long-press policy
Current state Accepted input or timing event Result
Ready Stable press begins Save start time; enter pressed state
Pressed Stable release before threshold Send short action once; return to ready
Pressed Threshold reached while held Send long action once; mark it sent
Long action sent Button remains held Send no further action
Long action sent Stable release Return to ready without a short action

This policy intentionally delays the short action until release. If the short action is sent immediately on the initial press, the program cannot later discover that the user intended only the long action without undoing something that already happened.

Microchip's long and short button-press example demonstrates duration-based interpretation. Its implementation is a technical reference; choose the application policy and timing for your own users rather than copying a threshold without testing it.

Specify the boundary case

What happens if the first observed stable release is exactly at the threshold? Define the answer. One reasonable policy classifies elapsed durations below the threshold as short and durations at or above it as long, while ensuring the event is emitted only once.

A sampled program cannot know every transition time perfectly. The scan interval and debounce policy affect the measured duration. Test close to the boundary and avoid promising timing precision that the input-processing system does not provide.

For example, a hypothetical 800 ms threshold is a design choice, not a universal human-interface standard. Try shorter and longer values with the intended enclosure and users. A tiny recessed button operated with a fingertip may feel different from the same switch held loose on a bench.

Keep the rest of the program responsive

Do not implement a long press by waiting in a loop until the user releases the button. That can stop display updates, communication and other input processing. Record a start timestamp and check elapsed time during the normal recurring program work.

On Arduino, the millis reference documents the unsigned millisecond counter and its rollover. Use appropriate unsigned elapsed-time arithmetic and keep servicing the classifier regularly. Store duration limits separately from absolute timestamps.

Test while the busiest normal operation runs. A long display update can delay both feedback and threshold detection. Logging every raw sample may also change timing, so use restrained diagnostics or suitable measurement equipment when investigating responsiveness.

Give feedback before adding more gestures

Show that the press has been recognised and distinguish entry into the long-action state. A display message, an existing indicator or another appropriate cue can tell the user when to release. The button itself need not be illuminated for the interface to provide feedback.

Avoid adding double-click, triple-click and several hold durations merely because one input can technically encode them. Every extra interpretation creates timing conflicts and learning effort. If users repeatedly guess the gesture, another control or a clearer menu may be a better design.

Test cancellation, reset and repeated use

Test short taps, long holds, releases close to the threshold and several presses in sequence. Confirm that one long hold produces one long command and no short command. Include a press during startup and decide whether the system waits for release before becoming ready.

If changing screens cancels an in-progress gesture, clear its state deliberately. Do not carry an old press timestamp into a new mode where release has a different meaning. Save the gesture policy and boundary tests with the project so later software changes preserve the intended behaviour.

Previous article Battery Power for Arduino Projects: Voltage Range, Runtime and Regulator Heat