write(analog-pwm)

koadrobot/ports/write(analog-pwm)

No description
write(analog-pwm)
@/write(analog-pwm)
PORTport
Digital port to read from. Should start with `D` to succeed.
DUTYnumber
Value in range 0 … 1
UPDpulse
Triggers new read
PULLboolean
Hardware connection. pulldown (true) - High, pullup (false) - Low (1-duty).
write(analog-pwm)
PORT
DUTY
UPD
PULL
DONE
ERR
ERRpulse
Fires if write failed. E.g. `PORT` does not exist.
DONEpulse
Fires on writing complete
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))
    {
        const uint8_t port = getValue<input_PORT>(ctx);

        Number duty = getValue<input_DUTY>(ctx);

        if (digitalPinHasPWM(port) || duty>=0 || duty<=1)
        {
            int val = (int)(duty * 255);

            if (!getValue<input_PULL>(ctx)) val = 255 - val;

            ::analogWrite(port, val);

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