kled(lum)

koadrobot/devices/kled(lum)

No description
kled(lum)
@/kled(lum)
PORTport
Board port number the LED is connected to. The port should be capable of generating PWM signal. Digital Port is On if Lum > 0.
LUMnumber
Luminance (brightness) value in relative units [0.0, 1.0].
UPDpulse
Triggers new write
PULLboolean
Hardware connection. pulldown (true) - High, pullup (false) - Low (1-duty).
kled(lum)
DONE
ERR
PORT
LUM
UPD
PULL
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/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 {
};

{{ GENERATED_CODE }}

void evaluate(Context ctx)
{
    if (isInputDirty<input_UPD>(ctx))
    {
        const uint8_t port = getValue<input_PORT>(ctx);

        Number lum = getValue<input_LUM>(ctx);

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

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

            // if port has not pwm, val >0.5 is High on digitalpin.
            ::analogWrite(port, val);

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