Stores a number which gets incremented on each `INC` pulse.
AVG=SUM/IDX
counter(avg)
@/counter(avg)
Stores a number which gets incremented on each `INC` pulse.
AVG=SUM/IDX
STEPnumber
Value to add on each increment. Use a negative value (e.g. -1) to make decrements.
INCpulse
Triggers a single step.
RSTpulse
Resets the counting value to start.
AVGnumber
IDXnumber
The counting index value.
SUMnumber
To use the node in your project you should have the koadrobot/aritmatics 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 avg ;
if (isInputDirty<input_RST>(ctx))
{
sum = 0;
idx = 0;
avg = 0;
}
else if (isInputDirty<input_INC>(ctx))
{
sum += getValue<input_STEP>(ctx);
idx++;
avg = sum / idx;
}
emitValue<output_SUM>(ctx, sum);
emitValue<output_IDX>(ctx, idx);
emitValue<output_AVG>(ctx, avg);
}