Help making a melody [SOLVED]

I need some help with coding a song. I already coded all that I possibly could, and it plays about 7 notes, then freezes. If I reset, it will play those SAME 7 notes and freeze. If you guys need I will copy my code onto here. I'm just wondering what could be causing the issue.

If you guys need I will copy my code onto here. I'm just wondering what could be causing the issue.

What if some of the ladies need it?

Why didn't you just post your code in the first place? If something is freezing, it is either an environmental issue, like my back yard, or a coding problem.

If it is an environmental issue, you will simply have to wait for spring. If it's a coding issue, well, you know what to do.

OK here it is. I don't have anything for loop because I have no knowledge on how to effectively loop a song. BTW I used some of the coding from the melody that came with the software. I'm using an Arduino UNO. Yes I know that the melody line is VERY long.

 #include "pitches.h"
int melody[] = {
  NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4, NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4, 0, NOTE_D5, NOTE_F5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4, 0, NOTE_E5, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_A4, NOTE_A4, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4, 0, NOTE_D5, NOTE_F5, NOTE_A5, NOTE_G5, NOTE_F5, NOTE_E5, NOTE_C5, NOTE_E5, NOTE_D5, NOTE_C5, NOTE_B4, NOTE_B4, NOTE_C5, NOTE_D5, NOTE_E5, NOTE_C5, NOTE_A4, NOTE_A4, 0, NOTE_E4, NOTE_C4, NOTE_D4, NOTE_B3, NOTE_C4, NOTE_A3, NOTE_GS3, NOTE_B3, NOTE_E4, NOTE_C4, NOTE_D4, NOTE_B3, NOTE_C4, NOTE_E4, NOTE_A4, NOTE_GS4};
int noteDurations[] = {
  4,8,8,4,8,8,4,8,8,4,8,8,4,8,4,4,4,4,2,8,4,8,4,8,8,4,8,4,8,8,4,8,8,4,4,4,4,4,4,8,8,4,8,8,4,8,8,4,8,8,4,8,4,4,4,4,2,8,4,8,4,8,8,4,8,4,8,8,4,8,8,4,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,4,4,2,1};
void setup() {
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);
    int pauseBetweenNotes = noteDuration * 1.10;
    delay(pauseBetweenNotes);
    noTone(8);
  }
}
void loop() {
}

You're only telling it to play 7 notes.
for (int thisNote = 0; thisNote < 8; thisNote++)
bump up 8 to the number of notes you have listed +1

OK thank you. I'm new to the Arduino and had no clue what values did what.

Instead of putting in a fixed value you can have it use the length of the array:

#define MELODY_COUNT (sizeof(melody)/sizeof(int))
#define DURATION_COUNT (sizeof(noteDurations)/sizeof(int))

  for (int thisNote = 0; thisNote < MELODY_COUNT; thisNote++) {

You may want to put in some code to check that MELODY_COUNT and DURATION_COUNT are equal. If they are not your two arrays don't match.

You could also put both melody and duration in the same array so they would be easier to edit together:

struct note {int melody, int duration};

struct note Notes[] = {
{NOTE_E5, 4},
{NOTE_B4, 8),
...
{NOTE_GS4, 1} };

#define NOTE_COUNT (sizeof(Notes)/sizeof(struct note))

Then use Notes[n].melody and Notes[n].duration instead of melody[n] and noteDurations[n].

That's awesome John. Wish that kind of info was posted in this tutorial.

{NOTE_B4, 8),

How long is a 8)?

PaulS:

{NOTE_B4, 8),

How long is a 8)?

Darn smilies. :frowning:

void setup() {
}

void loop() {
  for (int thisNote = 0; thisNote < 8; thisNote++) {
    int noteDuration = 1000/noteDurations[thisNote];
    tone(8, melody[thisNote],noteDuration);
    int pauseBetweenNotes = noteDuration * 1.10;
    delay(pauseBetweenNotes);
    noTone(8);
  }
}

OK it's solved I don't need anymore help.