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 |
|---|---|
Name (name) |
Name displayed on the block in the editor. Leaving the field empty displays click-analyzer. |
Time limit (time_limit) |
Required long-press threshold. Set the time using the days, hours, minutes, seconds, and milliseconds fields together; on save, they are added up to a total number of milliseconds. The total time must be a positive integer number of milliseconds. 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 timer for the duration set in “Time limit” starts when the press is detected
- if the input remains in the true state for at least the duration set in “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 the duration set in “Time limit” elapses, the block additionally triggers the short-release output
- if the release happens after the duration set in “Time limit” elapses, 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 the duration set in “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 the duration set in “Time limit” elapses. |
| 5. Long release. | A short logical pulse false -> true -> false generated when the button is released after the duration set in “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 before the duration set in “Time limit” elapsedreleased (long)means the last release happened after the duration set in “Time limit” elapsed
Errors returned by the block
The block may return the following errors:
| Error code | Error description |
|---|---|
Invalid time_limit. |
“Time limit” is missing, does not specify a valid integer number of milliseconds, 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” is set to 500 ms, then an input change
false -> truefollowed bytrue -> falseafter 200 ms triggers the outputs: Press, Release, and Short release. - If “Time limit” is set to 500 ms, then an input change
false -> 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 the duration set in “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.