v-stopuhr

hio/nwt-gus-hi/v-stopuhr

A simple timer/stopwatch
v-stopuhr
@/v-stopuhr
A simple timer/stopwatch
AnAusboolean
Enabled or not. If set to `false` pulses on `UPD` do not change the output value. Effectively that means the timer is paused. Set to `true` again to continue time counting.
Neustartpulse
Resets the current time value to zero.
Updatepulse
Triggers the time value update.
v-stopuhr
Zeit
AnAus
Neustart
Update
Zeitnumber
The current time value in seconds.
To use the node in your project you should have the hio/nwt-gus-hi 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

node {
    TimeMs lastUpdateTime;

    void evaluate(Context ctx) {
        bool enabled = getValue<input_AnAus>(ctx);
        bool update = isInputDirty<input_Update>(ctx);
        bool reset = isInputDirty<input_Neustart>(ctx);

        TimeMs t = transactionTime();
        if (reset)
            emitValue<output_Zeit>(ctx, 0);
        else if (enabled && update) {
            Number dtSeconds = (t - lastUpdateTime) / 1000.0;
            Number oldSeconds = getValue<output_Zeit>(ctx);
            emitValue<output_Zeit>(ctx, oldSeconds + dtSeconds);
        }

        lastUpdateTime = t;
    }
}