# Pulse throttle
Suppresses repeated pulses within a configurable discard period. The first pulse passes through and starts a cooldown window during which subsequent pulses are dropped. Useful for debouncing noisy signals or rate-limiting pulse outputs.
Pulse throttle
I
O
# Inputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
input | I | Input | BOOLEAN | false | Pulse signal. Only rising edges that arrive outside the discard period are forwarded. |
# Outputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
output | O | Output | BOOLEAN | false | Throttled pulse output. Mirrors the forwarded pulse shape. |
# Configuration
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
discard_period | Discard period | NUMBER | 0 | s | Cooldown window in seconds after forwarding a pulse. Pulses arriving during this window are dropped. Set to 0 to disable throttling. Details: ≥ 0 |
# State
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
prev_input | Previous input state | BOOLEAN | false | Stores the previous state of the input to detect rising and falling edges. | |
discarding | Discarding | BOOLEAN | false | Whether the block is currently in the cooldown window. |
# Source Code
View Volang source
channel = input::channel()
value = input::value()
extern fn onCallback(v) {
state::set("discarding", false)
}
if (channel == "input") {
prev_input = state::get("prev_input")
if (value and !prev_input) {
discarding = state::get("discarding")
if (!discarding) {
output::set("output", true)
discard_ms = math::round(config::get("discard_period") * 1000)
if (discard_ms > 0) {
state::set("discarding", true)
callback::set(discard_ms, "onCallback", 0)
}
}
}
if (!value and prev_input) {
output::set("output", false)
}
state::set("prev_input", value)
}
