read(digital)

koadrobot/ports/read(digital)

No description
read(digital)
@/read(digital)
PORTport
Analog port to read from. Should start with `A` to succeed.
UPDpulse
Triggers new read
PullUpboolean
Activate pullup resistor.
PULLboolean
Hardware connection. pulldown (true) - High, pullup (false) - Low (1-duty).
read(digital)
SIG
DONE
ERR
PORT
UPD
PullUp
PULL
ERRpulse
Fires if update failed. E.g. `PORT` does not exist.
DONEpulse
Fires on reading complete
SIGboolean
The last read signal value
To use the node in your project you should have the koadrobot/ports 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) 
{
    if (!isInputDirty<input_UPD>(ctx))
        return;

    const uint8_t port = getValue<input_PORT>(ctx);

    if (isValidDigitalPort(port))
    {
        if (getValue<input_PullUp>(ctx))
            ::pinMode(port, INPUT_PULLUP);
        else
            ::pinMode(port, INPUT);

        bool val = ::digitalRead(port);

        if (getValue<input_PULL>(ctx))
            emitValue<output_SIG>(ctx, val);
        else
            emitValue<output_SIG>(ctx, !val);

        emitValue<output_DONE>(ctx, 1);
    }
    else
        emitValue<output_ERR>(ctx, 1);
}