Set the Counters

I have two Counters in my project that count down time when triggered from the System Time node. One is set for 86400 or 24 hours and the other one is set to 1800 for 30 minutes, what I would like to do is reset or set the timers back to their initial values rather than zero when the Counters have hit zero. The Counters have a RST but no SET Pin so is there another node I could use or how could I add a SET Pin to the Counter nodes.

Thanks

You could create a new count node that provides a reset value pin, or you could just count up. You can still display count down by using max_val - count

Thank you for your reply. I’m very new to XOD and I’m not sure what to do with your max_val-count suggestion and I’m very weak in C++ so here’s one of the things I’ve tried. I created a new node and copied the Count node C++ exactly and then added some code as in the one example below.

if (isInputDirty<input_SET>(ctx))
count = getValue<output_OUT>(ctx);

I then changed the next line from an “if” to an “else if” but no matter what my first lines are I’m getting C++ Compile errors and it won’t upload to the Arduino.

Setting count equal to the output pin OUT isn’t going to do anything since OUT is set to count.

If you want to specify an initial count value, you will need to add a new input pin (maybe RVAL for Reset VALue), then replace

count = 0;

with

count = getValue<input_RVAL>(ctx);

If you just want to use existing nodes to do the same thing:

image

The output of the subtract node will run from 1800 to 0. You will need additional code to reset the counter when subtract output gets to 0.

Here is an example that will count seconds from 1800 to 0, then reset to 1800 and repeat:

image

Note that I used the less-or-equal node. When working with floating point numbers, one should never just use equal. 0.9999999999999 will show as 1, but it will not be equal to 1.

Thanks for your help. I was able to make a custom counter node that starts with the value in the OUT box and another value in a SET box so that when the node is RST it picks up the second value. This is exactly what I need for this project.


struct State {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    Number count = getValue<output_OUT>(ctx);

    if (isInputDirty<input_RST>(ctx))
    {
        count = getValue<input_SET>(ctx);
        emitValue<output_OUT>(ctx, count);
    }  
    else if (isInputDirty<input_INC>(ctx))
        count += getValue<input_STEP>(ctx);
   
    emitValue<output_OUT>(ctx, count);
}