debounce(boolean)

xod/core/debounce(boolean)

Debounces a boolean value. The `OUT` value would change only after a period of at least `Ts` seconds while which the input state `ST` has not changed. The node is useful to fight signal bouncing of mechanical switches.
debounce(boolean)
@/debounce(boolean)
Debounces a boolean value. The `OUT` value would change only after a period of at least `Ts` seconds while which the input state `ST` has not changed. The node is useful to fight signal bouncing of mechanical switches.
STboolean
Input bouncing boolean state.
Tsnumber
Debounce time in seconds.
debounce(boolean)
OUT
ST
Ts
OUTboolean
Debounced value.

C++ implementation

node {
    bool state = false;

    void evaluate(Context ctx) {
        bool x = getValue<input_ST>(ctx);

        if (x != state) {
            state = x;
            TimeMs dt = getValue<input_Ts>(ctx) * 1000;
            setTimeout(ctx, dt);
        }

        if (isTimedOut(ctx)) {
            emitValue<output_OUT>(ctx, x);
        }
    }
}