counter(max)

koadrobot/logic/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.
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.
counter(max)
STEP
MAX
INC
RST
SUM
IDX
END
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);

}

Tabular tests

INCRSTSTEPMAXSUMIDXEND
pulseno-pulse1311no-pulse
pulseno-pulse1322no-pulse
pulseno-pulse1333pulse
pulseno-pulse1333pulse
no-pulsepulse1300no-pulse
pulseno-pulse1311no-pulse
no-pulseno-pulse1311no-pulse
pulsepulse1300no-pulse