debounce(number)

xod/core/debounce(number)

Debounces a number value. The `OUT` value would change only after a period of at least `Ts` seconds while which the input state `ST` has not changed.
debounce(number)
@/debounce(number)
Debounces a number value. The `OUT` value would change only after a period of at least `Ts` seconds while which the input state `ST` has not changed.
STnumber
Value to debounce.
Tsnumber
Debounce time in seconds.
debounce(number)
OUT
ST
Ts
OUTnumber

C++ implementation

node {
    Number state = 0;

    void evaluate(Context ctx) {
        Number 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);
        }
    }
}

Tabular tests

__time(ms)STTsOUT
0010
1000110
2001111
2002211
3003212
5000222
5001322
600030.52
700230.53
800050.13
810150.15