A bidirectional counter with limits and a user definable reset value.
inc-dec-count-with-limits
@/inc-dec-count-with-limits
A bidirectional counter with limits and a user definable reset value.
STEPnumber
Value to add on each increment or to substract on each decrement.
MINnumber
lowest value of the count.
MAXnumber
hightest value of the count.
INITnumber
The value the count gets when there is a pulse on RST
INCpulse
Triggers a single increment.
DECpulse
Triggers a single decrement.
RSTpulse
Resets the accumulated value to the INIT value
OUTnumber
The accumulated value.
To use the node in your project you should have the bjbaylon/utilities-for-menus 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
struct State {
};
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
Number count = getValue<output_OUT>(ctx);
if (isInputDirty<input_RST>(ctx))
if (getValue<input_INIT>(ctx) < getValue<input_MIN>(ctx))
count = getValue<input_MIN>(ctx);
else count = getValue<input_INIT>(ctx);
else if (isInputDirty<input_INC>(ctx))
{count += getValue<input_STEP>(ctx);
if (count > getValue<input_MAX>(ctx))
count = getValue<input_MIN>(ctx);
}
else if (isInputDirty<input_DEC>(ctx))
{count -= getValue<input_STEP>(ctx);
if (count < getValue<input_MIN>(ctx))
count = getValue<input_MAX>(ctx);
}
if (count < getValue<input_MIN>(ctx))
count = getValue<input_MIN>(ctx);
emitValue<output_OUT>(ctx, count);
}