Skip to content

buzzer lib #6584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2025
Merged

buzzer lib #6584

merged 2 commits into from
Jul 12, 2025

Conversation

X-croot
Copy link
Contributor

@X-croot X-croot commented Jul 12, 2025

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

#include <BuzzerXCR.h>

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
void loop() {
  buzzer.serialControl('\n');
  delay(10);
}

@github-actions github-actions bot added the topic: submission Add library to the list label Jul 12, 2025
@github-actions github-actions bot merged commit 567826b into arduino:main Jul 12, 2025
11 checks passed
Copy link
Contributor

Your submission has now been accepted! Thanks for your contribution to the Arduino Library Manager index.

The library(s) will be available for installation via Library Manager within a day's time.

You can check the logs from the Library Manager indexer for your library(s) here:
http://downloads.arduino.cc/libraries/logs/github.com/X-croot/BuzzerXCR/

github-actions bot pushed a commit that referenced this pull request Jul 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic: submission Add library to the list
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant