click-analyzer
Description
The click-analyzer block is used to analyze a logical signal representing the state of a button or another two-state input. It recognizes the moment of pressing, long pressing, and releasing the button and exposes these events on separate outputs.
The block has one input and six outputs. It does not require the use of inputs labeled with the tag block.
Configuration parameters
| Parameter name | Value |
|---|---|
time_limit |
Required parameter that defines the long-press threshold in milliseconds. It must be a positive integer greater than zero. If the button stays in the true state for at least this long, the block reports a long press. |
Input handling
The block requires at least one input connection. If the input is not connected to anything during initialization, the block enters the Input disconnected. error state.
The block supports only values that can be interpreted as logical true or false. Values that cannot be read as a logical state are ignored.
Detailed behavior:
- a
false -> truechange is treated as a press and immediately triggers the press output - the
time_limittimer starts when the press is detected - if the input remains in the true state for at least
time_limit, the block triggers the long-press output once - a
true -> falsechange is treated as a release and always triggers the release output - if the release happens before
time_limitelapses, the block additionally triggers the short-release output - if the release happens after
time_limitelapses, the block additionally triggers the long-release output - receiving the same value as before is ignored, so the block reacts only to an actual state change
- while the button remains pressed after a long press has been detected, the long-press signal is generated only once; continuing to hold the button does not generate additional pulses
- the last output of the block always reflects the current input state as a logical value
Block outputs
| Output number and name | Output description |
|---|---|
| 1. Press. | A short logical pulse false -> true -> false generated when the input changes from false to true. |
| 2. Long press. | A short logical pulse false -> true -> false generated after time_limit has elapsed if the input is still in the true state. |
| 3. Release. | A short logical pulse false -> true -> false generated when the input changes from true to false. |
| 4. Short release. | A short logical pulse false -> true -> false generated when the button is released before time_limit elapses. |
| 5. Long release. | A short logical pulse false -> true -> false generated when the button is released after time_limit elapses. |
| 6. Current input state. | The current logical value of the input. This output emits true when the input is active and false when the input is inactive. |
Block status description
The description shown under the block reflects the last recognized state:
readymeans the initial state after successful initializationpressedmeans the input is currently in the true statereleased (short)means the last release happened beforetime_limitelapsedreleased (long)means the last release happened aftertime_limitelapsed
Errors returned by the block
The block may return the following errors:
| Error code | Error description |
|---|---|
Invalid time_limit. |
The time_limit parameter is missing, is not a valid integer, or has a value less than or equal to zero. |
Input disconnected. |
No other block is connected to the block input. |
Examples
- If
time_limit = 500, then an input changefalse -> truefollowed bytrue -> falseafter 200 ms triggers the outputs: Press, Release, and Short release. - If
time_limit = 500, then an input changefalse -> true, keeping the state for 700 ms, and only then changingtrue -> falsetriggers the outputs: Press, Long press, Release, and Long release. - If the input remains in the true state longer than
time_limit, the Long press output is generated only once. - If the block receives
trueand then receivestrueagain without an earlierfalse, the second event is ignored.