Count with step at each INC pulse.
When RST pulse is received counting start (again).
When IDX reach MAX counting is ended and END pulse transmit.
counter(max)
@/counter(max)
Count with step at each INC pulse.
When RST pulse is received counting start (again).
When IDX reach MAX counting is ended and END pulse transmit.
STEPnumber
Value to increment or decrement on each INC. Step is absolute. If (Stop > Start) then increment. If (Stop < Start) then decrement.
MAXnumber
Max idx to count.
INCpulse
Triggers a single step.
RSTpulse
Resets the counting value to start.
ENDpulse
Fires on IDX reach MAX.
IDXnumber
The counting index value.
SUMnumber
The counting value.
To use the node in your project you should have the koadrobot/logic 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 sum = getValue<output_SUM>(ctx);
Number idx = getValue<output_IDX>(ctx);
Number max = getValue<input_MAX>(ctx);
if (isInputDirty<input_RST>(ctx))
{
sum = 0;
idx = 0;
}
else if (isInputDirty<input_INC>(ctx))
{
if (idx<max)
{
sum += getValue<input_STEP>(ctx);
idx++;
}
else if (idx==max)
emitValue<output_END>(ctx, 1);
}
emitValue<output_SUM>(ctx, sum);
emitValue<output_IDX>(ctx, idx);
}