play-tone

wayland/wio-terminal-buzzer/play-tone

Play a tone for a specified duration.
play-tone
@/play-tone
Play a tone for a specified duration.
TONEnumber
Time high (milliseconds).
Tnumber
Duration (milliseconds).
UPDpulse
Update. Triggers play.
play-tone
TONE
T
UPD
DONE
DONEpulse
Fires after tone played.
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 {
    void evaluate(Context ctx) {

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

        ::pinMode(WIO_BUZZER, OUTPUT);

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