Sunday, December 14, 2014

Tone music surprises






Hey all! It's almost Christmas and time for the traditional carols. I've found a 8Ω loudspeaker from an old PC and I went through a classic Arduino Sketch for beginners. I've optimized it a little bit. Moreover, I've translated into French/Italian the notes and introduced standardized length for durations and the possibility to add pauses.



The carols
And here are some carols that I've just encoded.

Silent Night
(German: Stille Nacht, French: Douce Nuit, Italian: Astro del ciel)

Popular Christmas carol, composed in 1818 by Franz Xaver Gruber to lyrics by Joseph Mohr. It was declared an intangible cultural heritage by UNESCO in March 2011.

Download this tone music for Arduino here.

Jingle Bells

This is one of the most known Christmas carols. It was written by James Lord Pierpont (1822–1893) and published under the title "One Horse Open Sleigh" in the autumn of 1857.

Download this tone music for Arduino here.


Hark! The herald-angels sing

Another very popular carol first appeared in 1739 in the collection "Hymns and Sacred Poems" by Charles Wesley. Successively, it has been adapted by many musicians among which we also find Felix Mendelssohn and William H. Cummings.

Download this tone music for Arduino here.


The sketch
In order to run the sketch for playing tone music with your Arduino, you need to download the following header files: pitches.hdurations.h


/*
 *  Adapted by Enrico Formenti
 *  from an original sketch by Tom Igoe
 *  
 *  BSD license, check license.txt for more information
 *  All text above must be included in any redistribution.
 *
 *  See macduino.blogspot.com for more details.
 */

#include "pitches.h"
#include "durations.h"
#include "SilentNight.h"
 
#define TONEPIN 8

void setup() {
  
  for (int curNote = 0; curNote < melody_len; curNote++) {

    if(melody[curNote])
      tone(TONEPIN, melody[curNote],noteDurations[curNote]);
    else {
      noTone(TONEPIN);
      delay(noteDurations[curNote]);
    }

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    delay(noteDurations[curNote] * 1.3);
    // stop the tone playing:
    noTone(TONEPIN);
  }
}

void loop() {
  // no need to repeat the melody.
}

The circuit
It is a real Arduino's classic. You need:

  • 1KΩ resistor 1/4W
  • 8Ω 1/4W loudspeaker
  • your Arduino and 3 cables
Here is the Fritzing scheme for the circuit



What's next
Indeed, I'm translating lots of tone music of various genres. So expect a post with lots of new music tones! In the meanwhile, you can send me your own, I will publish and credit all of them!

See also
Tone music: advanced playing software
Tone music: how to encode melodies
Tone music: changing the Tempo of your melodies


Enjoy!

Credits
The image opening this post comes from Amagico.com website and according to them it is believed to be in the public domain. The icons illustrating the three tone musics come from Wikipedia.com

No comments :

Post a Comment