d-latch
Description
The d-latch block works as a bistable switch controlled by input events. Each regular input event that matches the condition defined by the “Input edge” parameter toggles the output state between true and false.
The block has one input and one output. It does not require the use of inputs labeled with the tag block.
In addition to regular toggling, the block also supports commands sent from the command block:
set: sets the output state to truereset: sets the output state to false
Configuration parameters
| Parameter name | Value |
|---|---|
Name (name) |
Name displayed on the block in the editor. If left empty, d-latch is displayed. |
Input edge (input_edge) |
Required parameter that defines which input event should toggle the block state. Available values: rising, falling, both, true, false, null. |
Restore state after power loss (persistent_state) |
Optional boolean parameter with the value true or false. When set to true, after restart the block tries to restore the last persisted output state. The persistent save does not happen immediately, but about 10 minutes after the last change. If a restart or power loss happens earlier, an older state may be restored. When set to false, the state is not restored after restart. |
Meaning of the “Input edge” parameter:
rising: toggle after a change interpreted asfalse -> truefalling: toggle after a change interpreted astrue -> falseboth: toggle on every logical state changetrue: toggle after every input event whose new value can be interpreted as logical truefalse: toggle after every input event whose new value can be interpreted as logical falsenull: toggle only after receiving thenullvalue
Input handling
The block requires at least one input connection. If there is no connection, it enters the disconnected state and does not react to events.
Detailed operating rules:
- the
setcommand from thecommandblock sets the output state to true - the
resetcommand from thecommandblock sets the output state to false - a regular input event that matches the “Input edge” condition toggles the block state to the opposite of the current one
- for the values
rising,falling,both,true, andfalse, the input must be interpretable as a logical value; other values are ignored - for the
nullvalue, the block reacts only when the new input value isnull
Examples of values that can be interpreted logically include boolean values and the numbers 0 and non-zero.
Block outputs
The block has one output.
The current remembered block state appears on the output as a logical value:
- true after being set with the
setcommand - false after being set with the
resetcommand - the opposite of the previous value after each valid toggling event
If “Restore state after power loss” is enabled and the block state was previously persisted successfully, then after project startup the block restores that state and sends it again to the output.
Block status description
The description visible below the block shows its current state or a problem:
truewhen the current block state is onfalsewhen the current block state is offInput disconnected.when the block has no input connectionInvalid input_edge configuration.when the “Input edge” parameter is invalid or missing
Errors visible to the user
The block can display the following error messages:
| Error code | Error description |
|---|---|
Invalid input_edge configuration. |
The “Input edge” parameter is invalid or missing. |
Input disconnected. |
No other block is connected to the block input. |
Examples
- If “Input edge” is set to
rising, then the first input change from false to true will toggle the output to true, and the next rising edge will toggle it back to false. - If “Input edge” is set to
true, then every new input value interpreted as true will toggle the block state, even if the previous value was also interpreted as true. - If the
commandblock sends thesetcommand, the output will be set to true regardless of the “Input edge” parameter. - With a button connected to the input and “Input edge” set to
rising, consecutive button presses toggle the output state. Theresetcommand from an additional connectedcommandblock always sets the output to false, allowing a separate “off” control.