ezBuzzer Library

I am looking to use the ezBuzzer library Reference page Here. Git Hub page here for a project, just a beeper playback basically. I am finding that it doesn't always play the low notes, when they are played as a medium to short duration.

They can play fine, but when set to similar values as in the example I share here, you can hear that some are missed.

I was wondering if anyone knows what is is about the library that allows this to happen, and do you know if there is something I could do to stop it from missing notes?

/*
   Created by ArduinoGetStarted.com

   This example code is in the public domain

   Tutorial page: https://arduinogetstarted.com/library/arduino-melody-repeat-example
   Library References: https://arduinogetstarted.com/tutorials/arduino-buzzer-library

   This example uses a piezo buzzer:
   + play a melody on background
   + repeat the melody when it is ended
   + without using delay() function, this is a non-blocking example
*/

#include <ezBuzzer.h> // ezBuzzer library

const int BUZZER_PIN = 3;

ezBuzzer buzzer(BUZZER_PIN); // create ezBuzzer object that attach to a pin;

// notes in the melody:
int melody[] = {
  NOTE_E1, NOTE_E1, NOTE_E1,
  NOTE_E1, NOTE_E1, NOTE_E1,
  NOTE_E1, NOTE_G1, NOTE_C1, NOTE_D1,
  NOTE_E1,
  NOTE_F1, NOTE_F1, NOTE_F1, NOTE_F1,
  NOTE_F1, NOTE_E1, NOTE_E1, NOTE_E1, NOTE_E1,
  NOTE_E1, NOTE_D1, NOTE_D1, NOTE_E1,
  NOTE_D1, NOTE_G1
};

// note durations: 4 = quarter note, 8 = eighth note, etc, also called tempo:
int noteDurations[] = {
  10, 10, 10,
  10, 10, 10,
  10, 10, 10, 10,
  10,
  10, 10, 10, 10,
  10, 10, 10, 10, 10,
  10, 10, 10, 10,
  10, 10
};

int noteLength;

void setup() {
  Serial.begin(9600);
  noteLength = sizeof(noteDurations) / sizeof(int);
}

void loop() {
  buzzer.loop(); // MUST call the buzzer.loop() function in loop()

  if (buzzer.getState() == BUZZER_IDLE) { // if stopped
    buzzer.playMelody(melody, noteDurations, noteLength); // playing
  }
}

This code is just an amended version of the supplied example of Melody Repeat usage. Notes are missed and not even consistently, some may be missed and maybe not upon the next repeat.

10 is for 1/10 note, just another length. I want to get the code to work correctly with any length of note, i'm not looking for the correct note lengths here, thanks.

Yeah, you do hear them. All the notes play fine with your durations too. It seems to be when there are a lot of medium to short notes, then some will not get played. All of the defined notes are definitely audible, C1 has a frequency of 33 Hz, yeah, at 100ms it's a short low note.

I have tried this on an online emulator, Wokwi, and it works fine, without skipping the notes.

Any ideas on what might be going on?

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.