# Edge detector
Detects rising, falling, or both edges on a boolean input and generates a timed output pulse.
Edge detector
I
O
# Inputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
input | I | Input | BOOLEAN | false | Boolean signal to monitor for edge transitions. |
# Outputs
| ID | Abbrev | Name | Type | Default | Description |
|---|---|---|---|---|---|
output | O | Output | BOOLEAN | false | Pulse output. Goes high for the configured pulse duration when an edge is detected. |
# Configuration
| ID | Name | Type | Default | Unit | Description |
|---|---|---|---|---|---|
direction | Direction | ENUM | 0 | Which edge transitions to detect. Rising detects false-to-true, Falling detects true-to-false, Both detects any change. Details: Values: Rising, Falling, Both | |
pulse_duration | Pulse duration | NUMBER | 0.1 | s | Duration of the output pulse generated on each detected edge. Details: > 0 |
startup_delay | Startup delay | NUMBER | 0 | s | Time after system boot during which edge detection is suppressed. Prevents false triggers from peripherals initializing. Set to 0 to disable. 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 transitions. | |
initialized | Initialized | BOOLEAN | false | Tracks whether the block has received at least one input event. The first event establishes a baseline without triggering edge detection. |
# Source Code
View Volang source
channel = input::channel()
value = input::value()
extern fn onPulseEnd() {
output::set("output", false)
}
if (channel == "input") {
prev_input = state::get("prev_input")
initialized = state::get("initialized")
if (!initialized) {
state::set("prev_input", value)
state::set("initialized", true)
return
}
startup_delay = config::get("startup_delay")
if (startup_delay > 0 and time::uptime() < startup_delay) {
state::set("prev_input", value)
return
}
direction = config::get("direction") // 0=Rising, 1=Falling, 2=Both
edge_detected = false
if (direction == 0) {
edge_detected = value and !prev_input
} else if (direction == 1) {
edge_detected = !value and prev_input
} else {
edge_detected = (value and !prev_input) or (!value and prev_input)
}
state::set("prev_input", value)
if (edge_detected) {
callback::clear()
output::set("output", true)
pulse_ms = math::round(config::get("pulse_duration") * 1000)
callback::set(pulse_ms, "onPulseEnd")
}
}
