Go Down

Topic: Toreador March (Read 390 times) previous topic - next topic

UptownKitten

Greetings, I am wondering if anyone may, please help me with a little project I am doing. The project is supposed to play 'Toreador March' from FNAF, but I keep getting an error message saying "expected declaration before '}' token." Here is the code & hardware:

Code: [Select]
#include <pitches.h>

//Credit to : UptownKitten453 & the Arduino ToneMelody tutorial.
//https://www.arduino.cc/en/Tutorial/toneMelody

int melody[] = {
NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_F3, NOTE_C3, NOTE_G3, NOTE_C3, NOTE_F3, NOTE_E3, NOTE_D3, NOTE_G2, NOTE_C3, NOTE_B2, NOTE_D3
NOTE_B2, NOTE_G2, NOTE_A2, NOTE_D3, NOTE_F3, NOTE_A3, NOTE_A3, NOTE_E3, NOTE_Ab3, NOTE_E3,
NOTE_A3, NOTE_E3, NOTE_A3, NOTE_E3, NOTE_B2
};

int noteDurations[] = {
  4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
};

void setup () {
   // iterate over the notes of the melody:
  for (byte thisNote = 0; thisNote < 20; thisNote++) {

    // to calculate the note duration, take one second divided by the note type.
    //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
    int noteDuration = 1000 / noteDurations[thisNote];
    tone(8, melody[thisNote], noteDuration);

    // to distinguish the notes, set a minimum time between them.
    // the note's duration + 30% seems to work well:
    int pauseBetweenNotes = noteDuration * 1.30;
    delay(pauseBetweenNotes);
    // stop the tone playing:
    noTone(8);
  }
}

Grumpy_Mike

First error is you are missing a comma after NOTE_D3

Next error is that the variable NOTE_Ab3 has not been declared. So what is this supposed to mean?

Next isthat you have not written a loop function.

Finally that hardware is crap. Never connect a speaker to a pin without any current limiting.

Grumpy_Mike

The tone function can only drive one pin at a time so basically you can't use this function. If you want a two part tune you have to use sound generator software that can produce two or more tones at the same time. This ability is called polyphonic.

I have seen these in the past so I know these are available, search for them.

Go Up