Skip to content

X-croot/BuzzerXCR

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.


resim

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);
}