Skip to content

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 true
  • reset: 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 as false -> true
  • falling: toggle after a change interpreted as true -> false
  • both: toggle on every logical state change
  • true: toggle after every input event whose new value can be interpreted as logical true
  • false: toggle after every input event whose new value can be interpreted as logical false
  • null: toggle only after receiving the null value

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 set command from the command block sets the output state to true
  • the reset command from the command block 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, and false, the input must be interpretable as a logical value; other values are ignored
  • for the null value, the block reacts only when the new input value is null

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 set command
  • false after being set with the reset command
  • 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:

  • true when the current block state is on
  • false when the current block state is off
  • Input disconnected. when the block has no input connection
  • Invalid 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 command block sends the set command, 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. The reset command from an additional connected command block always sets the output to false, allowing a separate “off” control.