To use the node in your project you should have the wkov/colony 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 {
bool state = false;
bool next;
uint32_t last = 0;
uint32_t min;
void reset() {
next = false;
min = millis() % 1000;
}
void evaluate(Context ctx) {
if (isInputDirty<input_RST>(ctx)) {
reset();
emitValue<output_MS>(ctx, last = 0);
emitValue<output_DONE>(ctx, true);
} else if (isInputDirty<input_TGL>(ctx)) {
state = !state;
if (state) {
reset();
emitValue<output_MS>(ctx, last);
} else {
last = getValue<output_MS>(ctx);
}
} else if (state) {
uint32_t ms = (millis() - min + last) % 1000;
emitValue<output_MS>(ctx, ms);
if (ms > min) {
next = true;
} else if (next) {
emitValue<output_NEXT>(ctx, next = false);
}
}
}
}