buzzer-pulse

marcoaita/malibrary/buzzer-pulse

This node allows to use the buzzer on the Ks0183 keyestudio Multi-purpose Shield V1 Like the buzzer, It is just a wrapper around the tone command for Arduino, but it requires a pulse input and the buzzer only emits a beep for the duration of T seconds.
buzzer-pulse
@/buzzer-pulse
This node allows to use the buzzer on the Ks0183 keyestudio Multi-purpose Shield V1 Like the buzzer, It is just a wrapper around the tone command for Arduino, but it requires a pulse input and the buzzer only emits a beep for the duration of T seconds.
PORTport
FREQnumber
Tnumber
TRIGpulse
buzzer-pulse
PORT
FREQ
T
TRIG
DONE
DONEpulse
To use the node in your project you should have the marcoaita/malibrary 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) {
    auto port = getValue<input_PORT>(ctx);
    auto freq = getValue<input_FREQ>(ctx);
    auto duration= getValue<input_T>(ctx)*1000.0;
    
    if (isInputDirty<input_TRIG>(ctx)) {
        pinMode(port, OUTPUT);
        tone(port, freq, duration);
        delay(duration); // tone is not blocking so we need this to have the DONE pulse at the end of sound, not at the beginning
        emitValue<output_DONE>(ctx, true);  //emits a pulse when done producing sound
        pinMode(port, INPUT);                 // put the output into a tri-state to silence even stubborn buzzers (this works whatever the driving transistor is, PNP or NPN)
    } else {
        noTone(port);
    }
}