# Variable Delayed Pulse

Process

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

IDAbbrevNameTypeDefaultDescription
inputIInputBOOLEANfalseTrigger signal. A rising edge starts the delayed pulse sequence.
delayDDelayNUMBER0Delay duration in seconds before the output pulse. 0 means immediate pulse.

# Outputs

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

# Configuration

IDNameTypeDefaultUnitDescription
pulseDuration of output pulseNUMBER0.1sDuration of the output pulse 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(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)
    }
}
Generates a delayed pulse at the output when triggered by a rising edge. Delay duration is provided via input.