Fires if update failed. E.g. `PORT` does not exist.
DONEpulse
Fires on reading complete
PRSboolean
Last read value. Equals to `true` while the button is pressed (hold down) and `false` while it is released.
To use the node in your project you should have the koadrobot/devices 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 {
bool state = false;
};
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
if (!isInputDirty<input_UPD>(ctx))
return;
const uint8_t port = getValue<input_PORT>(ctx);
if (!isValidDigitalPort(port)) {
emitValue<output_ERR>(ctx, 1);
return;
}
::pinMode(port, INPUT);
bool x = (::digitalRead(port));
State* state = getState(ctx);
if (x != state->state) {
state->state = x;
TimeMs dt = getValue<input_Ts>(ctx) * 1000;
setTimeout(ctx, dt);
}
if (isTimedOut(ctx)) {
if (getValue<input_PULL>(ctx))
emitValue<output_PRS>(ctx, x);
else
emitValue<output_PRS>(ctx, !x);
emitValue<output_DONE>(ctx, 1);
}
}