kled(sig-8)

koadrobot/devices/kled(sig-8)

No description
kled(sig-8)
@/kled(sig-8)
P7port
Led Port 7
P6port
Led Port 6
P5port
Led Port 5
P4port
Led Port 4
P3port
Led Port 3
P2port
Led Port 2
P1port
Led Port 1
P0port
Led Port 0
BITSbyte
Bits of which led will be turn on.
PULLboolean
HW connection of leds: False:Pullup (Anot to VCC).
UPDpulse
Triggers new write
kled(sig-8)
P7
P6
P5
P4
P3
P2
P1
P0
BITS
PULL
UPD
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/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 isAllPortsValid = false;
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) 
{

    if (isInputDirty<input_UPD>(ctx))
    {
        uint8_t ports[8];

        State* state = getState(ctx);
        
        if (isSettingUp)
        {
            ports[7] = getValue<input_P7>(ctx);
            ports[6] = getValue<input_P6>(ctx);
            ports[5] = getValue<input_P5>(ctx);
            ports[4] = getValue<input_P4>(ctx);
            ports[3] = getValue<input_P3>(ctx);
            ports[2] = getValue<input_P2>(ctx);
            ports[1] = getValue<input_P1>(ctx);
            ports[0] = getValue<input_P0>(ctx);
            state->isAllPortsValid = true;

            for(int i=0; i<8; i++)
            {
                if (isValidDigitalPort(ports[i]))
                {
                    ::pinMode(ports[i], OUTPUT);
                }
                else
                    state->isAllPortsValid = false;
            }
        }



        if (!state->isAllPortsValid)
        {
            emitValue<output_ERR>(ctx, 1);
            return;
        }

        uint8_t _out = getValue<input_BITS>(ctx);

        if(!getValue<input_PULL>(ctx)) _out ^= 0xFF;

  
        for(int i=0; i<8; i++)
            ::digitalWrite(ports[i], 1 & (_out >> i));

        emitValue<output_DONE>(ctx, 1);
    }

}