SparkFun Forums 

Where electronics enthusiasts find answers.

By brianuno
Any musician-programmers in the house? I need help with choosing tones. I have been following the SparkFun beginner tutorials. I'm as far as sounding a buzzer. The circuit is simple. Find a little Piezo device and plug the black wire into the Arduino board's ground pin hole. Plug the red wire into pin 8. Upload the sketch and it plays. Great! But not a catchy tune, imho. So, I decided to try a tune I know. That's where I got into trouble. Luckily, the SparkFun sketch includes a link to an Arduino tutorial, which includes a helpful library (link below). Without that library picking notes is guesswork. It was also my first attempt at copying library code to a new tab, naming and saving the file (pitches.h). For my first number, I will play Twinkle Twinkle Little Star. This is the code I am using:
Code: Select all
// notes in the melody:
int melody[] = {

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 4, 4, 4, 4, 4, 2
I seem to have the count, but the tones don't sound right to my ears. Can any musician-programmers suggest better code notes? I would like to write the whole piece. See attached original score. Thanks! ... m=Tutorial
You do not have the required permissions to view the files attached to this post.
By n1ist
The code doesn't match the score...
Try NOTE_G4, NOTE_G4, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_E5, NOTE_D5 ... rkbook.png
Though most versions I see on Google are
(I haven't played an instrument in years, so this is from long-forgotten memories...)
By brianuno
Thank you. I mean that because writing code, compared to cut-and-paste, is trying. I like your transcription of the notes better than the alternative provided. That pitch change to NOTE_A5, can't be intentional. I mean, try singing that. My friends would look at me.