# Delayed Pulse
Generuje opóźniony impuls na wyjściu po wyzwoleniu zboczem narastającym na wejściu
Delayed Pulse
I
O
# Wejścia
| ID | Skrót | Nazwa | Typ | Domyślnie | Opis |
|---|---|---|---|---|---|
input | I | Wejście | BOOLEAN | false | Sygnał wyzwalający. Zbocze narastające rozpoczyna sekwencję opóźnionego impulsu. |
# Wyjścia
| ID | Skrót | Nazwa | Typ | Domyślnie | Opis |
|---|---|---|---|---|---|
output | O | Wyjście | BOOLEAN | false | Sygnał wyjściowy impulsu. |
# Konfiguracja
| ID | Nazwa | Typ | Domyślnie | Jednostka | Opis |
|---|---|---|---|---|---|
delay | Czas opóźnienia | NUMBER | 2 | s | Czas opóźnienia przed wygenerowaniem impulsu wyjściowego Szczegóły: ≥ 0 |
pulse | Czas trwania impulsu | NUMBER | 0.1 | s | Czas trwania impulsu wyjściowego Szczegóły: ≥ 0 |
# Stan
| ID | Nazwa | Typ | Domyślnie | Jednostka | Opis |
|---|---|---|---|---|---|
last_input_state | Ostatni stan wejścia | BOOLEAN | false | Przechowuje poprzedni stan wejścia |
# Kod źródłowy
Pokaż kod Volang
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)
}
}
