# Pulse throttle
Pulse throttle
I
O
# 入力
| ID | 略称 | 名前 | 型 | デフォルト | 説明 |
|---|---|---|---|---|---|
input | I | input | BOOLEAN | false |
# 出力
| ID | 略称 | 名前 | 型 | デフォルト | 説明 |
|---|---|---|---|---|---|
output | O | output | BOOLEAN | false |
# 設定
| ID | 名前 | 型 | デフォルト | 単位 | 説明 |
|---|---|---|---|---|---|
discard_period | discard_period | NUMBER | 0 | s | 詳細: ≥ 0 |
# 状態
| ID | 名前 | 型 | デフォルト | 単位 | 説明 |
|---|---|---|---|---|---|
prev_input | prev_input | BOOLEAN | false | ||
discarding | discarding | BOOLEAN | false |
# ソースコード
Volang ソースを表示
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)
}
