Count with step at each INC pulse from start to stop.
When RST pulse is received counting start (again).
When IDX reach
MAX ((STOP-START)/STEP) counting is ended and END pulse transmit.
counter(start-stop)
@/counter(start-stop)
Count with step at each INC pulse from start to stop.
When RST pulse is received counting start (again).
When IDX reach
MAX ((STOP-START)/STEP) 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.
STARTnumber
Start Value to count.
STOPnumber
Stop Value to count.
INCpulse
Triggers a single step.
RSTpulse
Resets the counting value to start.
ENDpulse
Fires on IDX reach
MAX= (STOP-START)/STEP
TICKpulse
Fires on each for-count.
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 start = getValue<input_START>(ctx);
Number stop = getValue<input_STOP>(ctx);
Number step = getValue<input_STEP>(ctx);
Number sum = getValue<output_SUM>(ctx);
Number idx = getValue<output_IDX>(ctx);
Number max;
if (step==0)
max=0;
else
max = trunc((stop-start) / step);
if (isInputDirty<input_RST>(ctx))
{
sum = start;
idx = 0;
}
else if (isInputDirty<input_INC>(ctx) && max>0)
{
if (idx<max)
{
sum += step;
idx++;
emitValue<output_TICK>(ctx, 1);
}
else if (idx==max)
emitValue<output_END>(ctx, 1);
}
emitValue<output_SUM>(ctx, sum);
emitValue<output_IDX>(ctx, idx);
}