# Delay

Process

Delays the output state changes based on switch-on and switch-off delay durations

Delay
I
O

# Inputs

IDAbbrevNameTypeDefaultDescription
inputIInputBOOLEANfalseInput 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

IDAbbrevNameTypeDefaultDescription
outputOOutputBOOLEANfalseDelayed output signal. Switches ON after 'don' delay when input goes high, and switches OFF after 'doff' delay when input goes low.

# Configuration

IDNameTypeDefaultUnitDescription
donDuration switch-on delayNUMBER1sDelay duration before the output is switched ON when input goes high

Details:

≥ 0
doffDuration switch-off delayNUMBER1sDelay duration before the output is switched OFF when input goes low

Details:

≥ 0

# State

IDNameTypeDefaultUnitDescription
last_input_stateLast input stateBOOLEANfalseStores 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
}

Delays the output state changes based on switch-on and switch-off delay durations