Tuesday, February 8, 2011

Project 12 - Piezo Sounder Melody Player

A fun little project, but I have to say the Piezo buzzer is not my favorite choice of noisemaker. I'm not sure if the video quite captures just how grating the high pitch squeals really are...

One thing I really was glad to learn in this project was the ability to use the #define command to equate a value with a token. Similar, I guess, to a variable, but the value cannot be changed in the program (only at the #define statement). The author did a good job of explaining why this feature is useful with the dot matrix display example... makes sense if you think about it - substituting in a larger display is simple when all you have to do is change the height and width values in the #define statements.

It was also nice to be able to download the code rather than type it in - typing in all those #define statements followed by the tune and the duration information would have been tedious (probably good to do just to hammer in the idea, but I think I've got it...)

One thing I'm still not clear on, however, is the discussion of the length variable. The author divides 26 (notes) by 2 (the number of bytes in a single element) to get a value of 13. The loop will count from 0 to 13, playing the tune(x)... the way I'm reading this seems to indicate only the first 13 (of 26) notes will get played. Am I missing something?

I'm including a video below that I hope doesn't annoy anyone in the room (or office) - it's definitely Puff the Magic Dragon, but I'd never play this for my 8 month old with a Piezo!


  1. This is a mistake in the book, the "sizeof(tune)" gives the value of 52, so the value of "length" is 26 and not 13.
    You can see it if you use the Serial.print(length) command.

  2. This is a mistake in the book. The "sizeof(tune)" gives 52 , so the "length" is equal to 26 and not 13.
    You can check it out, if you put "Serial.print (length)" in the program.

  3. I needl Help ! I get errors on this code. First one: for (int x=0; x tone(8, tune[x]));
    delay (1500*duration[x]);

    I guess there is something wrong on the book because I put it just like its written.