Tuesday, December 3, 2024

Elevating your Buzzer Initiatives to the Subsequent Degree – Information


Bored with boring buzzers in your tasks? Right here’s a short have a look at how I used our Qwiic Buzzers to take my buzzers from Sleepy to Symphonic with the brand new SparkFun Qwiic Buzzer!

Elevating your Buzzer Initiatives to the Subsequent Degree – Information





Favorited



Favourite


0

Piezo buzzers are one of many easiest issues so as to add to any challenge, simply supplying you with a non-visual alert system. At its most simple, they are often so simple as blinking an LED – simply flip a digital pin on and off in your microcontroller, substitute the LED with a buzzer, and you’ve got an audible warning alarm. In the event you’ve labored with the Arduino “tone” library, then that by controlling the frequency despatched to the buzzer, you may change the pitch and truly play tunes. After all, one of many shortcomings is the truth that you may solely play one notice at a time. You could possibly join a number of buzzers to a number of pins, but it surely’s nonetheless solely potential to play one sound, from one buzzer, at a time.


SparkFun Qwiic Buzzer

Out of inventory


BOB-24474

The brand new SparkFun Qwiic Buzzer addresses these points. By including just a little circuitry to the board, together with an ATtiny84, and making it controllable by way of I2C, we’ve created what one Funion has referred to as “essentially the most over-engineered buzzer on this planet.” Nevertheless, for somebody like me who would possibly wish to do extra than simply single quantity, monophonic buzzer alerts, this new buzzer that is able to daisy-chaining and enjoying as much as 128 at a time is a dream come true.

alt text

Setup with a number of Qwiic Buzzers is quick and simple!

HOW IT WORKS

In the event you’ve labored with the tone library, then working with our Qwiic buzzer will really feel very acquainted. Whereas there are a couple of alternative ways to create sounds, the simplest is to create an integer array for each the notes and their period. Then it’s only a matter of making a “for” loop, matching the variety of loops to the variety of notes in your tune.

Writer’s warning: If utilizing this methodology for polyphonic buzzer songs, creating completely different rhythms, or notes of various durations, is difficult. On the finish of the “for” loop, there’s a delay, which we’ve discovered works finest at about 1.3 instances the size of the notice being performed. This delay applies to all notes, so it forces all notes to start out and cease on the similar time. This may be a problem in, say, the “B” part of the Tremendous Mario Brothers theme, the place the bass line adjustments, and differs from the highest two traces. It takes some inventive re-articulation, altering notice period values and including rests to make the whole lot line up. As soon as that was performed, nevertheless, the whole lot ran fairly easily.

alt text

Music notation software program may be extraordinarily useful for adjusting notice values to ensure all of them align.

AN EXAMPLE TO GET YOU STARTED

After I began engaged on the demo for the Qwiic Buzzer Video, I assumed, what must be “Whats up World!” of buzzers? The “Blink” sketch? The one logical answer appeared to be the Tremendous Mario Brothers theme.

I used three voices for this demo, so the very first thing we have to do is change the I2C addresses on two of the boards. That is simply performed utilizing instance 5. Then it’s on to the principle sketch. After importing the Qwiic Buzzer library, I created cases for every of the three buzzers. You’ll be able to title every one no matter works for you – voice1, voice2, voice3; excessive, medium, low; no matter works in your mind. For this instance I went with melodyBuzzer, harmonyBuzzer, and bassBuzzer. Subsequent, I created arrays for the notes of every of the three voices, and the durations of every notice. Relying on the size of your tune, this will wind up taking over most of your reminiscence. Whereas this instance will for on a SparkFun Redboard or Arduino Uno, if you wish to develop on this, or have a number of tune choices like I did within the video, you’ll undoubtedly wish to use a board with extra reminiscence, like a Redboard Artemis or one in every of our ESP32 boards. The setup loop is simply what you’d count on – provoke (.start) every buzzer occasion, be sure that they’re acknowledged, and also you’re good to go.

You’ll discover that the majority of the enjoying directions occur in a separate operate, referred to as void play_melody(). As soon as we have established the notes and their durations, that every one simply will get fed into this operate, and the tune performs!

WHAT THE CODE LOOKS LIKE

/*
 * SparkFun Qwiic Buzzer Polyphony Demo
 * 
 * This instance exhibits off the Qwiic Buzzer's means
 * to comtrol a number of buzzers concurrently by
 * enjoying a 3-part association of just a little little bit of
 * the Tremendous Mario Bros Theme.
 * 
 * By Rob Reynolds @ SparkFun Electronics
 * February 2024
 * 
 * {Hardware} connections:
 * Join three (3) SparkFun Qwiic Buzzers to you
 * microcontroller by way of the Qwiic connectors.
 * 
 * SparkFun code, firmware, and software program is launched beneath the MIT License.
 * Please see LICENSE.md for additional particulars.
 * 
 * This code is launched beneath the Beerware License. In the event you discover this code
 * helpful, and see me or every other Funion on the native, purchase us a beer!
 * 
 * Distributed as-is, with no guarantee * 
 * 
 */


#embody <SparkFun_Qwiic_Buzzer_Arduino_Library.h>  // Import the library for the Qwiic Buzzer
QwiicBuzzer melodyBuzzer; //0x34 (default)
QwiicBuzzer harmonyBuzzer; //0x35 (beforehand modified)
QwiicBuzzer bassBuzzer; //0x36  (beforehand modified)

// notes within the melody:
int melody[] = {
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_E5, 
  SFE_QWIIC_BUZZER_NOTE_C5, 
  SFE_QWIIC_BUZZER_NOTE_E5, 
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_REST,  // silence (aka "relaxation") 
  SFE_QWIIC_BUZZER_NOTE_G4, 
  SFE_QWIIC_BUZZER_NOTE_REST,  // silence (aka "relaxation")
  // "A" part begins right here***********************************
  SFE_QWIIC_BUZZER_NOTE_C5, 
  SFE_QWIIC_BUZZER_NOTE_REST,  // silence (aka "relaxation")
  SFE_QWIIC_BUZZER_NOTE_G4,
  SFE_QWIIC_BUZZER_NOTE_REST,  // silence (aka "relaxation")
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_REST,  // silence (aka "relaxation")
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_AS4,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_G4, //TRIPLETS START
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_A5,
  SFE_QWIIC_BUZZER_NOTE_F5,
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  // "A" part repeat begins right here ***********************
  SFE_QWIIC_BUZZER_NOTE_C5, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_G4,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_AS4,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_G4, //TRIPLETS START
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_A5,
  SFE_QWIIC_BUZZER_NOTE_F5,
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  //"B" Part begins right here**************************
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 7
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_FS5,
  SFE_QWIIC_BUZZER_NOTE_F5,
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 8
  SFE_QWIIC_BUZZER_NOTE_GS4,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 9
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_FS5,
  SFE_QWIIC_BUZZER_NOTE_F5,
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 10
  SFE_QWIIC_BUZZER_NOTE_C6,
  SFE_QWIIC_BUZZER_NOTE_C6,
  SFE_QWIIC_BUZZER_NOTE_C6,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 11
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_FS5,
  SFE_QWIIC_BUZZER_NOTE_F5,
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 12
  SFE_QWIIC_BUZZER_NOTE_GS4,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 13
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_C5,    //measure 14
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,
};

// Notes within the concord
int concord[] = {
  SFE_QWIIC_BUZZER_NOTE_FS4,
  SFE_QWIIC_BUZZER_NOTE_FS4,
  SFE_QWIIC_BUZZER_NOTE_FS4, 
  SFE_QWIIC_BUZZER_NOTE_FS4, 
  SFE_QWIIC_BUZZER_NOTE_FS4, 
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_REST,   
  SFE_QWIIC_BUZZER_NOTE_G3, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  // "A" part begins right here*********************************
  SFE_QWIIC_BUZZER_NOTE_E4, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_D4,
  SFE_QWIIC_BUZZER_NOTE_CS4,
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_C4, //TRIPLETS START
  SFE_QWIIC_BUZZER_NOTE_G4,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_D4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  // "A" part repeat begins right here*********************************
  SFE_QWIIC_BUZZER_NOTE_E4, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_D4,
  SFE_QWIIC_BUZZER_NOTE_CS4,
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_C4, //TRIPLETS START
  SFE_QWIIC_BUZZER_NOTE_G4,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_A4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_D4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  //"B" Part begins right here**************************
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 7
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 8
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_G4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 9
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 10
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_G5,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 11
  SFE_QWIIC_BUZZER_NOTE_E5,
  SFE_QWIIC_BUZZER_NOTE_DS5,
  SFE_QWIIC_BUZZER_NOTE_D5,
  SFE_QWIIC_BUZZER_NOTE_B4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_C5,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 12
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_G4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_REST,  //measure 13
  SFE_QWIIC_BUZZER_NOTE_GS4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_E4,    //measure 14
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,
  SFE_QWIIC_BUZZER_NOTE_REST,
};

// notes within the bass:
int bass[] = {
  SFE_QWIIC_BUZZER_NOTE_D3,
  SFE_QWIIC_BUZZER_NOTE_D3,
  SFE_QWIIC_BUZZER_NOTE_D3, 
  SFE_QWIIC_BUZZER_NOTE_D3, 
  SFE_QWIIC_BUZZER_NOTE_D3, 
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_REST,   
  SFE_QWIIC_BUZZER_NOTE_G2, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  // "A" part begins right here**********************************
  SFE_QWIIC_BUZZER_NOTE_G3, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_E3,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_C3,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_F3,
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_FS3,
  SFE_QWIIC_BUZZER_NOTE_F3,
  SFE_QWIIC_BUZZER_NOTE_E3, //TRIPLETS START
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_D4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_A3,
  SFE_QWIIC_BUZZER_NOTE_B3,
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_REST,
  // "A" part begins right here**********************************
  SFE_QWIIC_BUZZER_NOTE_G3, 
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_E3,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_C3,
  SFE_QWIIC_BUZZER_NOTE_REST,  
  SFE_QWIIC_BUZZER_NOTE_F3,
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_FS3,
  SFE_QWIIC_BUZZER_NOTE_F3,
  SFE_QWIIC_BUZZER_NOTE_E3, //TRIPLETS START
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_F4,
  SFE_QWIIC_BUZZER_NOTE_D4,
  SFE_QWIIC_BUZZER_NOTE_E4,
  SFE_QWIIC_BUZZER_NOTE_C4,
  SFE_QWIIC_BUZZER_NOTE_A3,
  SFE_QWIIC_BUZZER_NOTE_B3,
  SFE_QWIIC_BUZZER_NOTE_G3,
  SFE_QWIIC_BUZZER_NOTE_REST,
  // "B" part begins right here ***************************************
  // Numbers point out notice durations, only for my reference when writing
  SFE_QWIIC_BUZZER_NOTE_C3,    //4  measure 7
  SFE_QWIIC_BUZZER_NOTE_REST,  //8 
  SFE_QWIIC_BUZZER_NOTE_G3,    //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_C4,    //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_F3,    //4  measure 8
  SFE_QWIIC_BUZZER_NOTE_REST,  //16
  SFE_QWIIC_BUZZER_NOTE_REST,  //16
  SFE_QWIIC_BUZZER_NOTE_C4,    //8
  SFE_QWIIC_BUZZER_NOTE_C4,    //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_F3,    //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_C3,    //4  measure 9
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_G3,    //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_G3,    //8
  SFE_QWIIC_BUZZER_NOTE_C4,    //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //2  measure 10
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_G3,    //4
  SFE_QWIIC_BUZZER_NOTE_C3,    //4  measure 11
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_G3,    //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_C4,    //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_F3,    //4  measure 12
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_C4,    //8
  SFE_QWIIC_BUZZER_NOTE_C4,    //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_F3,    //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //4
  SFE_QWIIC_BUZZER_NOTE_C3,    //4  measure 13
  SFE_QWIIC_BUZZER_NOTE_GS3,   //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_AS3,   //4
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_C4,    //4  measure 14
  SFE_QWIIC_BUZZER_NOTE_REST,  //8
  SFE_QWIIC_BUZZER_NOTE_G3,    //8
  SFE_QWIIC_BUZZER_NOTE_G3,    //4
  SFE_QWIIC_BUZZER_NOTE_C3,    //4
};


// notice durations: 4 = quarter notice, 8 = eighth notice, and so forth.:
int marioNoteDurations[] = {
  8, 4, 4, 8, 4,    4, 4, 4, 4,
  4, 8, 4, 8, 4,    8, 4, 4, 8, 4,    6, 6, 6, 4, 8, 4,    4, 8, 8, 4, 8,
  4, 8, 4, 8, 4,    8, 4, 4, 8, 4,    6, 6, 6, 4, 8, 4,    4, 8, 8, 4, 8,  //begin "B" part subsequent line
  4, 8, 8, 8, 8, 8, 8,    8, 8, 8, 8, 8, 8, 8, 8,    4, 8, 8, 8, 8, 8, 8,    8, 4, 8, 4, 4,
  4, 8, 8, 8, 8, 8, 8,    8, 8, 8, 8, 8, 8, 8, 8,    4, 4, 8, 4, 8,     4, 8, 8, 4, 4
  // The prolonged areas above aren't essential, I take advantage of them to separate measures
  // merely to assist me preserve the music extra clear. Very useful for debugging!
};

void setup() {
  Serial.start(115200);
  Serial.println("Qwiic Buzzer Tremendous Mario Bros Pattern");
  Wire.start(); //Be part of I2C bus
  melodyBuzzer.start(0x34);
  harmonyBuzzer.start(0x35);
  bassBuzzer.start(0x36);

/*  
  // These are good for testing, I commented them out once I moved the challenge to stand-alone

  //examine if buzzer will join over I2C
  if (buzzer1.start() == false) {
    Serial.println("Buzzer 1 didn't join! Freezing.");
    whereas (1);
  }

  else if (buzzer2.start() == false) {
    Serial.println("Buzzer 2 didn't join! Freezing.");
    whereas (1);
  }

  else if (buzzer3.start() == false) {
    Serial.println("Buzzer 3 didn't join! Freezing.");
    whereas (1);
  }

*/
  Serial.println("Buzzers linked.");

  Serial.println("Buzzing Melody now...");
  play_melody();
}

void loop() {
  // do nothing right here
  // we simply play the melody as soon as throughout setup above.
}

void play_melody()
{
    // iterate over the notes of the melody:
  for (int thisNote = 0; thisNote < 103; thisNote++) {  // 51 for A piece solely (repeated), 97 for complete demo for whole melody/concord notes, add 8 rests to bass

    // to calculate the notice period, take one second divided by the notice sort.
    //e.g. quarter notice = 1000 / 4, eighth notice = 1000/8, and so forth.
    int melodyNoteDuration = 1000 / marioNoteDurations[thisNote];  // change quantity to alter tempo. <1000 = quicker; >1000 = slower

    melodyBuzzer.configureBuzzer(melody[thisNote], melodyNoteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
    melodyBuzzer.on();

    harmonyBuzzer.configureBuzzer(concord[thisNote], melodyNoteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
    harmonyBuzzer.on();

    bassBuzzer.configureBuzzer(bass[thisNote], melodyNoteDuration, SFE_QWIIC_BUZZER_VOLUME_MAX);
    bassBuzzer.on();



    // to differentiate the notes, set a minimal time between them.
    // the notice's period + 30% appears to work properly:
    int pauseBetweenNotes = melodyNoteDuration * 1.30;
    delay(pauseBetweenNotes);
  }
}

For musicians beginning out in coding, this may increasingly appear a bit overwhelming. In the event you’re a coder with out a lot of a background in music, this may increasingly appear equally daunting. Beneath is a graphic displaying the notes and their octaves. You’ll be able to lengthen beneath and above the notes proven, however that ought to offer you a superb place to begin. Notice additionally that we do not use F#, G#, and so forth, relatively we use FS, GS, and so forth, due to the #’s place in C++.

alt text

Notes and their octaves. Since we will not use # as an unintentional, we is S to point sharps.

NOW IT’S YOUR TURN TO CREATE

This sketch is a good place to begin. From right here, all it is advisable do to create a brand new tune is change the values of the notes and their durations. And whereas that will appear to be quite a bit – every notice requires a line that appears like

SFE_QWIIC_BUZZER_NOTE_C4,
  • all it is advisable do is change the notice worth itself, ie C4 turns into E5. Then arrow down, a few backspaces, repeat, and you may truly get by way of it fairly shortly.

A few issues that I discovered extraordinarily useful through the course of embody commenting measure numbers when creating the “notes” integers, or at the least commenting very clear sections. You will discover within the above sketch that I remark when every new part begins, and when the triplets begin within the “A” part. In defining the durations, I’ve put additional areas between values to point measure separations. Once more, this is not in any respect essential, I simply discover it extraordinarily useful when debugging your code, determining the place you may have unsuitable notes or unsuitable notice values, issues like that.

Right here some examples at across the 9:00 mark.

I will be including a pull request in our Github repo to be sure that everybody who desires it has entry to this code. In the event you’ve give you some superb buzzer tunes, I encourage you to do the identical. I ended at three Qwiic Buzzers for my demo, however that does not imply that it is advisable. If anybody desires to deal with, say, Bernstein’s Overture to Candide, or Mussorgsky’s Footage at an Exhibition, I might be each excited and terrified to listen to that!

Cowl picture: SparkFun Qwiic Buzzer debuting on the Joan and Sanford I. Weill Recital Corridor, Carnagie Corridor, NYC. Recital corridor picture courtesy of Carnagie Corridor Group.

Related Articles

1 COMMENT

  1. Hi,

    I just came across your uncommunication.com website. I really like the cool design and usability of it. It’s really nice.

    This is Cyrus. I worked as a Social Media Management specialist. We specialized in constantly updating the social media profiles of brands over the last few years using eye catching images and engaging captions. By doing this habit, it builds trust when people see that you have an updated social media handles. Trust builds confidence for customers. And when they are confident, they are likely to convert into customers.

    I’d be happy to give you a test drive of our service. A total of 7 free social media posts.

    I would love the chance to discuss how we can contribute to the growth of uncommunication.com through effective social media management. Are you available for a quick conversation to explore this further? I’d be delighted to get in touch.

    All the best,
    Cyrus Sandoval
    Social Media Management Specialist
    cy**************@gm***.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles