# Delayed Pulse
Generates a delayed pulse at the output when triggered by a rising edge on the input
Delayed Pulse
I
O
# Inputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
input | I | Input | BOOLEAN | false | Input trigger signal. A rising edge starts the delayed pulse sequence. |
# Outputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
output | O | Output | BOOLEAN | false | Output pulse signal. Goes high after the configured delay duration and stays high for the configured pulse duration. |
# Configuration
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
delay | Duration of delay | NUMBER | 2 | s | Delay duration before the output pulse is generated after a rising edge on the input Details: ≥ 0 |
pulse | Duration of output pulse | NUMBER | 0.1 | s | Duration of the output pulse that is 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(config::get("delay") * 1000)
// Handle callback execution
extern fn onCallback(value) {
if (value == 1) {
// Delay complete - start output pulse
pulse_ms = math::round(config::get("pulse") * 1000)
output::set("output", true)
if (pulse_ms > 0) {
callback::set(pulse_ms, "onCallback", 2)
} else {
// Zero pulse duration - immediately turn off
output::set("output", false)
}
return
}
if (value == 2) {
// Pulse complete - turn off output
output::set("output", false)
return
}
}
// Handle input changes - detect rising edge
if (channel == "input") {
last_input_state = state::get("last_input_state")
// Detect rising edge
if (value and !last_input_state) {
state::set("last_input_state", true)
// Cancel any pending callbacks and reset output
callback::clear()
output::set("output", false)
// Schedule delay
if (delay_ms > 0) {
callback::set(delay_ms, "onCallback", 1)
} else {
// Zero delay - immediately start pulse
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)
}
}
}
// Track falling edge
if (!value and last_input_state) {
state::set("last_input_state", false)
}
}
