buzzer-play-tone

wayland/rp2040/buzzer-play-tone

Use buzzer to play tone.
buzzer-play-tone
@/buzzer-play-tone
Use buzzer to play tone.
TONEnumber
Time high (milliseconds).
Tnumber
Duration (milliseconds).
UPDpulse
Update. Triggers play.
buzzer-play-tone
TONE
T
UPD
DONE
DONEpulse
Fires after tone played.
To use the node in your project you should have the wayland/rp2040 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 {

    const int buzzerPin = 19;
    
    void evaluate(Context ctx) {

        if (!isInputDirty<input_UPD>(ctx))
            return;

        ::pinMode(buzzerPin, OUTPUT);

        int tone = getValue<input_TONE>(ctx);
        int duration = getValue<input_T>(ctx);
        
        for (long i = 0; i < duration * 1000L; i += tone * 2) {
            ::digitalWrite(buzzerPin, HIGH);
            delayMicroseconds(tone);
            ::digitalWrite(buzzerPin, LOW);
            delayMicroseconds(tone);
        }
        
        emitValue<output_DONE>(ctx, 1);
    }
}