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 |
|---|---|
Trigger edge (input_edge) |
Required parameter that defines which input event should toggle the block state. Supported values are: rising, falling, both, true, false, null, none. |
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 thenullvaluenone: disable the reaction to regular input events
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_edgecondition 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 - for the
nonevalue, all regular input events are ignored, but thesetandresetcommands still work
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 persistent_state 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 theinput_edgeparameter 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 = 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 = 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 theinput_edgeparameter. - If
input_edge = none, regular input events will not change the block state, but theresetcommand will still set the output to false.