# Variable Delayed Pulse
Generates a delayed pulse at the output when triggered by a rising edge. Delay duration is provided via input.
Variable Delayed Pulse
I
D
O
# Inputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
input | I | Input | BOOLEAN | false | Trigger signal. A rising edge starts the delayed pulse sequence. |
delay | D | Delay | NUMBER | 0 | Delay duration in seconds before the output pulse. 0 means immediate pulse. |
# Outputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
output | O | Output | BOOLEAN | false | Pulse signal. Goes high after the delay and stays high for the configured pulse duration. |
# Configuration
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
pulse | Duration of output pulse | NUMBER | 0.1 | s | Duration of the output pulse generated after the delay. Details: ≥ 0 |
# State
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
last_input_state | Last input state | BOOLEAN | false | Stores the previous state of the input to detect rising edges. |
# Source Code
View Volang source
channel = input::channel()
value = input::value()
delay_ms = math::round(input::get("delay") * 1000)
extern fn onCallback(value) {
if (value == 1) {
pulse_ms = math::round(config::get("pulse") * 1000)
output::set("output", true)
if (pulse_ms > 0) {
callback::set(pulse_ms, "onCallback", 2)
} else {
output::set("output", false)
}
return
}
if (value == 2) {
output::set("output", false)
return
}
}
if (channel == "input") {
last_input_state = state::get("last_input_state")
if (value and !last_input_state) {
state::set("last_input_state", true)
callback::clear()
output::set("output", false)
if (delay_ms > 0) {
callback::set(delay_ms, "onCallback", 1)
} else {
pulse_ms = math::round(config::get("pulse") * 1000)
output::set("output", true)
if (pulse_ms > 0) {
callback::set(pulse_ms, "onCallback", 2)
} else {
output::set("output", false)
}
}
}
if (!value and last_input_state) {
state::set("last_input_state", false)
}
}
