# Delay
Delays the output state changes based on switch-on and switch-off delay durations
Delay
I
O
# Inputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
input | I | Input | BOOLEAN | false | Input signal that triggers the delayed output. When high, output will be delayed by 'don' duration. When low, output will be delayed by 'doff' duration. |
# Outputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
output | O | Output | BOOLEAN | false | Delayed output signal. Switches ON after 'don' delay when input goes high, and switches OFF after 'doff' delay when input goes low. |
# Configuration
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
don | Duration switch-on delay | NUMBER | 1 | s | Delay duration before the output is switched ON when input goes high Details: ≥ 0 |
doff | Duration switch-off delay | NUMBER | 1 | s | Delay duration before the output is switched OFF when input goes low 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 edges |
# Source Code
View Volang source
channel = input::channel()
value = input::value()
don_ms = math::round(config::get("don") * 1000)
doff_ms = math::round(config::get("doff") * 1000)
// Handle callback execution
extern fn onCallback(value) {
if (value == 1) {
// Delay on callback - set output to true
output::set("output", true)
return
}
if (value == 2) {
// Delay off callback - set output to false
output::set("output", false)
return
}
}
// Handle input changes - detect edges
if (channel == "input") {
last_input_state = state::get("last_input_state")
// Only react to state changes (edges)
if (value != last_input_state) {
state::set("last_input_state", value)
if (value) {
// Input went high - schedule delay on
callback::clear()
if (don_ms > 0) {
callback::set(don_ms, "onCallback", 1)
} else {
// If delay is 0, set output immediately
output::set("output", true)
}
} else {
// Input went low - schedule delay off
callback::clear()
if (doff_ms > 0) {
callback::set(doff_ms, "onCallback", 2)
} else {
// If delay is 0, set output immediately
output::set("output", false)
}
}
}
return
}
