count-inc-dec-limit

stefanc1991/essentials-a/count-inc-dec-limit

No description
count-inc-dec-limit
@/count-inc-dec-limit
Startnumber
Starting number
Stepnumber
Step size. Add/subtract this number.
Minnumber
Minimum. Lower limit for output.
Maxnumber
Maximum. Upper limit for output.
Addpulse
On pulse, add step size to current count.
Subtractpulse
On pulse, subtract step size from current count.
Resetpulse
On pulse, reset count to Start value.
count-inc-dec-limit
Start
Step
Min
Max
Add
Subtract
Reset
Count
Done
Donepulse
Pulse on completion.
Countnumber
Current count.
To use the node in your project you should have the stefanc1991/essentials-a library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

// based on https://xod.io/libs/ivanmason/lcd16x2x5button/updowncount/

#pragma XOD dirtieness disable

node {
    // Internal state variables defined at this level persists across evaluations
    Number count;

    void evaluate(Context ctx) {
        if(isInputDirty<input_Reset>(ctx)) {
            count = getValue<input_Start>(ctx);
        }
        
        if(isInputDirty<input_Add>(ctx)){
            count += getValue<input_Step>(ctx);
        }

        if(isInputDirty<input_Subtract>(ctx)){
            count -= getValue<input_Step>(ctx);
        }

        if (count > getValue<input_Max>(ctx)) {
            count = getValue<input_Max>(ctx);
        }

        if (count < getValue<input_Min>(ctx)) {
            count = getValue<input_Min>(ctx);
        }

        emitValue<output_Count>(ctx, count);
        emitValue<output_Done>(ctx, 1);
    }
}