buzzer-pwm-write

wayland/wio-terminal-buzzer/buzzer-pwm-write

Send analog signal to buzzer.
buzzer-pwm-write
@/buzzer-pwm-write
Send analog signal to buzzer.
DUTYnumber
Duty cycle value in range 0.0 … 1.0
UPDpulse
Triggers new write
buzzer-pwm-write
DUTY
UPD
DONE
DONEpulse
Fires on writing complete
To use the node in your project you should have the wayland/wio-terminal-buzzer 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

#pragma XOD evaluate_on_pin disable
#pragma XOD evaluate_on_pin enable input_UPD

node {
    #ifdef PWMRANGE
    static constexpr Number pwmRange = PWMRANGE;
    #else
    static constexpr Number pwmRange = 255.0;
    #endif

    void evaluate(Context ctx) {
 
        if (!isInputDirty<input_UPD>(ctx))
            return;

        auto duty = getValue<input_DUTY>(ctx);
        duty = duty > 1 ? 1 : (duty < 0 ? 0 : duty);
        int val = (int)(duty * pwmRange);

        pinMode(WIO_BUZZER, OUTPUT);
        analogWrite(WIO_BUZZER, val);

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