# Delayed Pulse

Process

Generates a delayed pulse at the output when triggered by a rising edge on the input

Delayed Pulse
I
O

# Inputs

IDAbbrevNameTypeDefaultDescription
inputIInputBOOLEANfalseInput trigger signal. A rising edge starts the delayed pulse sequence.

# Outputs

IDAbbrevNameTypeDefaultDescription
outputOOutputBOOLEANfalseOutput pulse signal. Goes high after the configured delay duration and stays high for the configured pulse duration.

# Configuration

IDNameTypeDefaultUnitDescription
delayDuration of delayNUMBER2sDelay duration before the output pulse is generated after a rising edge on the input

Details:

≥ 0
pulseDuration of output pulseNUMBER0.1sDuration of the output pulse that is generated after the delay

Details:

≥ 0

# State

IDNameTypeDefaultUnitDescription
last_input_stateLast input stateBOOLEANfalseStores 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)
    }
}
Generates a delayed pulse at the output when triggered by a rising edge on the input