Home Electronics Elevating your Buzzer Initiatives to the Subsequent Stage – Information

Elevating your Buzzer Initiatives to the Subsequent Stage – Information

0
Elevating your Buzzer Initiatives to the Subsequent Stage – Information

[ad_1]

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





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 elementary, they are often so simple as blinking an LED – simply flip a digital pin on and off in your microcontroller, change the LED with a buzzer, and you’ve got an audible warning alarm. In case you’ve labored with the Arduino “tone” library, then you already know that by controlling the frequency despatched to the buzzer, you may change the pitch and really play tunes. After all, one of many shortcomings is the truth that you may solely play one word at a time. You can join a number of buzzers to a number of pins, however it’s nonetheless solely potential to play one sound, from one buzzer, at a time.


SparkFun Qwiic Buzzer

Solely 5 left!


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.” Nonetheless, for somebody like me who may need to do extra than simply single quantity, monophonic buzzer alerts, this new buzzer that is able to daisy-chaining and taking part in as much as 128 at a time is a dream come true.

alt text

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

HOW IT WORKS

In case you’ve labored with the tone library, then working with our Qwiic buzzer will really feel very acquainted. Whereas there are a number of other ways to create sounds, the best is to create an integer array for each the notes and their length. 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 greatest at about 1.3 occasions the size of the word being performed. This delay applies to all notes, so it forces all notes to begin and cease on the similar time. This may be a difficulty in, say, the “B” part of the Tremendous Mario Brothers theme, the place the bass line adjustments, and differs from the highest two strains. It takes some artistic re-articulation, altering word length values and including rests to make every part line up. As soon as that was carried out, nonetheless, every part ran fairly easily.

alt text

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

AN EXAMPLE TO GET YOU STARTED

Once I began engaged on the demo for the Qwiic Buzzer Video, I believed, what ought to be “Hey World!” of buzzers? The “Blink” sketch? The one logical resolution 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 carried out utilizing instance 5. Then it’s on to the principle sketch. After importing the Qwiic Buzzer library, I created situations for every of the three buzzers. You may identify each no matter works for you – voice1, voice2, voice3; excessive, medium, low; no matter works on 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 word. Relying on the size of your music, this could wind up taking on most of your reminiscence. Whereas this instance will for on a SparkFun Redboard or Arduino Uno, if you wish to broaden on this, or have a number of music choices like I did within the video, you’ll positively need to use a board with extra reminiscence, like a Redboard Artemis or certainly one of our ESP32 boards. The setup loop is simply what you’d count on – provoke (.start) every buzzer occasion, ensure they’re acknowledged, and also you’re good to go.

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

WHAT THE CODE LOOKS LIKE

/*
 * SparkFun Qwiic Buzzer Polyphony Demo
 * 
 * This instance reveals off the Qwiic Buzzer's skill
 * to comtrol a number of buzzers concurrently by
 * taking part in 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 case you discover this code
 * helpful, and see me or another Funion on the native, purchase us a beer!
 * 
 * Distributed as-is, with no guarantee * 
 * 
 */


#embrace <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 word 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
};


// word durations: 4 = quarter word, 8 = eighth word, and many others.:
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 vital, I exploit them to separate measures
  // merely to assist me hold the music extra clear. Very useful for debugging!
};

void setup() {
  Serial.start(115200);
  Serial.println("Qwiic Buzzer Tremendous Mario Bros Pattern");
  Wire.start(); //Be a 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

  //verify 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 related.");

  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 bit solely (repeated), 97 for total demo for complete melody/concord notes, add 8 rests to bass

    // to calculate the word length, take one second divided by the word kind.
    //e.g. quarter word = 1000 / 4, eighth word = 1000/8, and many others.
    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 tell apart the notes, set a minimal time between them.
    // the word's length + 30% appears to work properly:
    int pauseBetweenNotes = melodyNoteDuration * 1.30;
    delay(pauseBetweenNotes);
  }
}

For musicians beginning out in coding, this may occasionally appear a bit overwhelming. In case you’re a coder with out a lot of a background in music, this may occasionally appear equally daunting. Beneath is a graphic exhibiting the notes and their octaves. You may prolong under and above the notes proven, however that ought to offer you an excellent start line. Observe additionally that we do not use F#, G#, and many others, somewhat we use FS, GS, and many others, due to the #’s place in C++.

alt text

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

NOW IT’S YOUR TURN TO CREATE

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

SFE_QWIIC_BUZZER_NOTE_C4,
  • all it is advisable to do is change the word worth itself, ie C4 turns into E5. Then arrow down, a few backspaces, repeat, and you may really get by it fairly rapidly.

A few issues that I discovered extraordinarily useful in the course of the course of embrace commenting measure numbers when creating the “notes” integers, or at the least commenting very clear sections. You may 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 further areas between values to point measure separations. Once more, this is not in any respect vital, I simply discover it extraordinarily useful when debugging your code, determining the place you’ve improper notes or improper word values, issues like that.

I will be including a pull request in our Github repo to ensure that everybody who desires it has entry to this code. In case you’ve provide you with some wonderful 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 to. If anybody desires to deal with, say, Bernstein’s Overture to Candide, or Mussorgsky’s Footage at an Exhibition, I’d 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.

[ad_2]