lr-fast-pwm

hussainfawzi/fast-pwm/lr-fast-pwm

No description
lr-fast-pwm
@/lr-fast-pwm
PORTport
Select the Port to use for PWM
FREQUENCYnumber
Set the frequency (range 0Hz - 500kHz)
DUTYnumber
Set the duty cycle (range 0 - 255)
UPDATEpulse
Feed a pusle along with required frequency and duty cycle.
lr-fast-pwm
PORT
FREQUENCY
DUTY
UPDATE
DONE
DONEpulse
Spits a pulse when done
To use the node in your project you should have the hussainfawzi/fast-pwm 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_UPDATE>(ctx))
        return;
    const uint8_t port = getValue<input_PORT>(ctx);
    if (!isValidDigitalPort(port)) {
        raiseError(ctx);
        return;
    };
    auto duty = getValue<input_DUTY>(ctx);
    if(duty>255){duty=255;}
    if(duty<0){duty=0;}
    auto freq = getValue<input_FREQUENCY>(ctx);
    SetPinFrequencySafe(port, freq);
    pwmWrite(port, duty);
    emitValue<output_DONE>(ctx, 1);
};