NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Playing different music with the MCU

April 05, 2011
by lnino
lnino's Avatar

Hi at all.

I tried to make some sound with the Tutorial "Making Sound with a Microcontroller" and I was successful with playing the Happy Birthday melody.

Now I thought it would be nice to play a different sound, but I have now clue about how to interpret the music. Where do I get the A5, D5,..... and so on from?

I thought about doing theme music of monkey island, maniac mansion, leisure suite larry. Is there a way to get those A5, D5,... or exists a programm which can filter those after playing such a theme?

Thanks for the help.

April 05, 2011
by hariharan
hariharan's Avatar

Inino, If you are talking about the notes, then the website is http://www.phy.mtu.edu/~suits/notefreqs.html when you get the frequency, do 1000000/2/the frequency. for example, if the frequency is 1000 hz, do 1000000/2/1000 which is 500. What you found is the half period of the frequency.

April 05, 2011
by lnino
lnino's Avatar

Thanks for your reply hariharan.

What I meant is, how do I realize it when I have somehting like this? HERE THERE

Or how would be the procedure, when I say: "I want my microcontroller to play Indiana Jones, or Monkey Island". What steps do I have to do? Because I am no musician I am a little bit helpless.

Maybe somebody is here to be able to help me out.

April 05, 2011
by bretm
bretm's Avatar

Wikipedia image

This shows the notes C4 through C5 (and then back down to C4 again) as shown on a treble clef. Does that help?

It goes C4, D4, E4, F4, G4, A4, B4, C5, B4, A4, G4, F4, E4, D4, C4 in the picture.

April 06, 2011
by lnino
lnino's Avatar

Hi bretm,

thanks for the reply. That helped a lot.

Now I have another question:

Why the word Happy has only one D5 in the "Making Sound with a Microcontroller" Tutorial?

lcd_quick_clear_and_home();
lcd_write_string(PSTR("  Happy ")); play_tone(D5, DUR);
lcd_write_string(PSTR("birth"));    play_tone(E5, DUR);
lcd_write_string(PSTR("day ")); play_tone(D5, DUR);
lcd_write_string(PSTR("to "));  play_tone(G5, DUR);
lcd_write_string(PSTR("you ")); play_tone(Fsh5, 2*DUR);

On the screenshot below Happy has two notes. In this case Happy Birthday is written in a different way. So "Happy Birthday To You" in this case would be G4 A4 G4 C5 B4. Right?

Because I am no musician I don't know why this is handled like that.

How should be such double notes interpreted?

Because in some themes I would like to realize are many of them. And do I have to think about how long every note should be played?

Happy Birthday

Maybe somone has an idea.

Thanks a lot.

April 07, 2011
by lnino
lnino's Avatar

Hi at all.

I got now a little bit more familiar with programming sounds on the MCU. I was now able to get "The Final Countdown" working. It's not perfect, but it was a quite nice learning effect.

Have fun.

    // Final Countdown
    play_tone(Csh6, DUR/2);
    play_tone(B5, DUR/2);
    play_tone(Csh6, DUR/2);
    play_tone(Fsh5, 2*DUR);

    play_tone(D6, DUR/2);
    play_tone(Csh6, DUR/2);
    play_tone(D6, DUR/2);
    play_tone(Csh6, DUR/2);
    play_tone(B5, 2*DUR);

    play_tone(D6, DUR/2);
    play_tone(Csh6, DUR/2);
    play_tone(D6, DUR/2);
    play_tone(Fsh5, 2*DUR);

    play_tone(B5, DUR/2);
    play_tone(A5, DUR/2);                   
    play_tone(B5, DUR/2);
    play_tone(A5, DUR/2);
    play_tone(Gsh5, DUR/2);
    play_tone(B5, DUR/2);
    play_tone(A5, 2*DUR);

    play_tone(Gsh5, DUR/2); 
    play_tone(A5, DUR/2);
    play_tone(B5, 2*DUR);

    play_tone(A5, DUR/2);
    play_tone(B5, DUR/2);
    play_tone(Csh6, DUR/2); 
    play_tone(B5, DUR/2);
    play_tone(A5, DUR/2);
    play_tone(Gsh5, DUR/2);
    play_tone(Fsh5, 2*DUR);

    play_tone(D6, 2*DUR);   
    play_tone(Csh6, 2*DUR);

    play_tone(Csh6, DUR);
    play_tone(Csh6, DUR);
    play_tone(D6, DUR);
    play_tone(Csh6, DUR/2);
    play_tone(B5, DUR/2);
    play_tone(Csh6, 2*DUR);
April 07, 2011
by bretm
bretm's Avatar

Well done.

Post a Reply

Please log in to post a reply.

Did you know that you can input numbers in binary via a DIP switch, and output them to the LCD? Learn more...