https://github.com/x-croot/buzzerxcr
Arduino buzzer library
https://github.com/x-croot/buzzerxcr
arduino arduino-buzzer arduino-library buzzer buzzer-controllers
Last synced: about 1 month ago
JSON representation
Arduino buzzer library
- Host: GitHub
- URL: https://github.com/x-croot/buzzerxcr
- Owner: X-croot
- License: mit
- Created: 2025-07-12T22:09:38.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2025-07-12T22:30:29.000Z (12 months ago)
- Last Synced: 2025-07-13T00:19:30.958Z (12 months ago)
- Topics: arduino, arduino-buzzer, arduino-library, buzzer, buzzer-controllers
- Language: C++
- Homepage:
- Size: 8.79 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BuzzerXCR
**BuzzerXCR** is an advanced Arduino library for controlling passive buzzers with extended sound effects, PWM-based volume control, and built-in LED feedback support. Designed for alarms, games, sound indicators, and musical effects, it provides a rich set of features for sound manipulation.
---

## Features
* Easy-to-use API for passive buzzers
* Volume control via PWM (optional)
* LED feedback support (optional)
* Sound effects:
* Slow, Normal, Fast **Distortion**
* **Fade In** / **Fade Out**
* **Glissando** transitions
* Scheduled notes
* Melody playback from arrays
* Serial Terminal interaction with commands (e.g., `BEEP`, `FREQ 440`, `STOP`)
* Debug output support for development
---
## Installation
1. Clone or download this repository as a `.zip`
2. Open Arduino IDE
3. Go to **Sketch > Include Library > Add .ZIP Library...**
4. Select the downloaded zip file
---
## Example Usage
```cpp
#include
BuzzerXCR buzzer(9, 8); // Buzzer pin, LED pin
void setup() {
buzzer.begin(20);
buzzer.setVolume(80);
buzzer.sound(NOTE_C4, 500);
buzzer.fadeIn(NOTE_E4, 1000);
buzzer.distortion(NOTE_C4, NOTE_G4, FAST);
}
void loop() {}
```
---
## Function Overview
### `begin(int pausePercent)`
Sets the pause percentage between notes.
### `end(int ms)`
Delays for `ms` milliseconds at the end of a melody.
### `sound(int note, int duration)`
Plays a tone of given frequency (`note`) and duration (ms).
### `fadeIn(int note, int duration)`
Starts sound from low volume and increases gradually.
### `fadeOut(int note, int duration)`
Starts at full volume and decreases to silence.
### `distortion(int fromNote, int toNote, DistortionSpeed speed)`
Creates a sweeping tone between two notes with chosen speed (`SLOW`, `NORMAL`, `FAST`).
### `glissando(int fromNote, int toNote, int totalDuration)`
Smooth pitch slide between notes.
### `playMelody(const int* notes, const int* durations, int count)`
Plays an array of notes with corresponding durations.
### `vibratePattern(const int* pattern, int count)`
Plays a series of short tones and pauses, simulating vibration.
### `scheduleNote(int note, int duration, int delayMs)`
Schedules a note to play after a specified delay.
### `setVolume(int percent)`
Sets the buzzer volume (0–100%) using PWM.
### `enablePWMVolume(bool enable)`
Turns on or off PWM-based volume control.
### `setToneCurve(String curveType)`
Sets tone shaping method (e.g., `"linear"`).
### `debugMode(bool enable)`
Prints debug messages over Serial when enabled.
### `serialControl(char delimiter)`
Reads Serial commands like `BEEP`, `FREQ 440`, `STOP`.
### `toString()`
Returns a string representation of the current BuzzerXCR object state.
---
## Serial Commands (in loop)
* `BEEP` - short beep
* `FREQ 440` - plays 440 Hz tone
* `STOP` - stops current tone
```cpp
void loop() {
buzzer.serialControl('\n');
delay(10);
}
```
---