A library to easily make beeps with a Buzzer.
Fixes and new features as well as support for more platforms will be included in further releases.
Currently supports the Esp32
platform only.
Support for these others platforms will be added Arduino
Particle Photon
Particle Electron
#include <EasyBuzzer.h>
By default, the library is configured to use the pin number 4. You may change the default pin number, modifying the value of DEFAULT_PIN
in Config.h file. To set the pin number on the sketch, call the function EasyBuzzer.setPin(pin)
on the setup.
int pin = 2;
void setup() {
EasyBuzzer.setPin(pin);
};
void loop() {
/* Always call this function in the loop for EasyBuzzer to work. */
EasyBuzzer.update();
};
Beep continuously at a given frequency.
/* Beep continuously at a given frequency. */
EasyBuzzer.beep(
frequency // Frequency in Hertz(HZ).
);
Beep at a given frequency an specific number of times.
/*
Beep at a given frequency an specific number of times.
The default onDuration and offDuration is set in Config.h file.
*/
EasyBuzzer.beep(
frequency, // Frequency in Hertz(HZ).
beeps // The number of beeps.
);
Beep at a given frequency an specific number of times, with callback functionality.
/*
Beep at a given frequency an specific number of times, with callback functionality.
The default onDuration and offDuration is set in Config.h file.
*/
EasyBuzzer.beep(
frequency, // Frequency in Hertz(HZ).
beeps, // The number of beeps.
callback // [Optional] Function to call when done.
);
Create a sequence of beeps at a given frequency.
/* Create a sequence of beeps at a given frequency. */
EasyBuzzer.beep(
frequency, // Frequency in hertz(HZ).
onDuration, // On Duration in milliseconds(ms).
offDuration, // Off Duration in milliseconds(ms).
beeps, // The number of beeps per cycle.
pauseDuration, // Pause duration.
cycles, // The number of cycle.
callback // [Optional] Function to call when done.
);
Single beep at a given frequency, for an specific duration.
/* Single beep. */
EasyBuzzer.singleBeep(
frequency, // Frequency in hertz(HZ).
duration // Duration of the beep in milliseconds(ms).
);
Single beep at a given frequency, for an specific duration, with callback functionality.
/* Single beep at a given frequency, for an specific duration, with callback functionality. */
EasyBuzzer.singleBeep(
frequency, // Frequency in hertz(HZ).
duration, // Duration of the beep in milliseconds(ms).
callback // [Optional] Function to call when done.
);
Use this function to stop the beeping. You may call this function at all time, everywhere in the code.
EasyBuzzer.stopBeep();
The default duration values are defined in the Config.h file. You may change those values on the Config.h file or use the provided function to change them.
EasyBuzzer.setDuration(onDuration, offDuration, pauseDuration);