read(analog)

koadrobot/ports/read(analog)

No description
read(analog)
@/read(analog)
PORTport
Analog port to read from. Should start with `A` to succeed.
UPDpulse
Triggers new read
PULLboolean
Hardware connection. pulldown (true) - High, pullup (false) - Low (1-duty).
read(analog)
PORT
UPD
PULL
DUTY
DONE
ERR
ERRpulse
Fires if update failed. E.g. `PORT` is not an ADC port.
DONEpulse
Fires on writing complete
DUTYnumber
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 (isValidAnalogPort(port))
    {
        ::pinMode(port, INPUT);
        Number val = :::analogRead(port) / 1023.;

        if (getValue<input_PULL>(ctx))
            emitValue<output_DUTY>(ctx, val);
        else
            emitValue<output_DUTY>(ctx, 1.0-val);

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