Go Down

Topic: Play Melody (Read 3183 times) previous topic - next topic

SarahBethC

I switched to the Arduino "Melody" example code and I'm getting an error that says

 
error: expected declaration before '}' token

 };

I've changed my code 30 times and nothing is working....do any of you know what this means and how to fix it??? Its olny highlighting:

  #define Note_e4 329.63

There are 35ish more notes exactly like that with different frequencies and a different name (instead of being Note_e4 it'll be Note_f3, etc.). I don't know what is wrong with my code that only that part is messed up....

CrossRoads

Well, you could post/attach the code for us to look at and identify where the missing ; needs to go.

Are you sure Melody works with non-whole #s like 329.63?
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SarahBethC

so , did you made it or not in the end?
Still working on it.

Grumpy_Mike

Quote
error: expected declaration before '}' token
Normally means a ; or a } misplaced.

If you click on a { then the matching } is highlighted, they must be matched.

SarahBethC

Here is the program I have written. I haven't tried it with whole #s because I don't want the pitches to be off.....

uxomm

The commas are missing in the melody array.

If you add them like this
Code: [Select]
// notes in the melody:
int melody[] = {
Note_g4, Note_e4, Note_f4, Note_g4, Note_a4, Note_c5, Note_b4, Note_f5, Note_c6, Note_c5, Note_d5, Note_eb5, Note_f5, Note_g5, Note_a5, Note_bb5, Note_a5, Note_g5, Note_f5, Note_e5, Note_d5, Note_c5, Note_b4, Note_a4, Note_g5, Note_a5, Note_b5, Note_c6, Note_b5, Note_a5, Note_g5, Note_b5, Note_c6, Note_d6, Note_e6, Note_d6, Note_c6, Note_b5, R, Note_d6, Note_f5, Note_d6, Note_a5, Note_d6, Note_a5, Note_c6, Note_d5
};

the code will compile.
Always decouple electronic circuitry.

SarahBethC

The commas are missing in the melody array.

If you add them like this
Code: [Select]
// notes in the melody:
int melody[] = {
Note_g4, Note_e4, Note_f4, Note_g4, Note_a4, Note_c5, Note_b4, Note_f5, Note_c6, Note_c5, Note_d5, Note_eb5, Note_f5, Note_g5, Note_a5, Note_bb5, Note_a5, Note_g5, Note_f5, Note_e5, Note_d5, Note_c5, Note_b4, Note_a4, Note_g5, Note_a5, Note_b5, Note_c6, Note_b5, Note_a5, Note_g5, Note_b5, Note_c6, Note_d6, Note_e6, Note_d6, Note_c6, Note_b5, R, Note_d6, Note_f5, Note_d6, Note_a5, Note_d6, Note_a5, Note_c6, Note_d5
};

the code will compile.
I tried it that way, but it didn't work....

CrossRoads

Code: [Select]
int melody[] = {
 R,Note_g4, Note_e4, Note_f4, Note_g4, Note_a4, Note_c5, Note_b4, Note_f5, Note_c6, Note_c5, Note_d5, Note_eb5, Note_f5, Note_g5, Note_a5, Note_bb5, Note_a5, Note_g5, Note_f5, Note_e5, Note_d5, Note_c5, Note_b4, Note_a4, Note_g5, Note_a5, Note_b5, Note_c6,  Note_b5, Note_a5, Note_g5, Note_b5, Note_c6, Note_d6, Note_e6, Note_d6, Note_c6, Note_b5, Note_d6, Note_f5, Note_d6, Note_a5, Note_d6, Note_a5, Note_c6, Note_d5,
};

Compiles ok for me with IDE 1.6.9
R is in a different position, I thought it was a typo when I was adding commas, I don't know from where so I stuck it at the beginning.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

SarahBethC

Code: [Select]
int melody[] = {
 R,Note_g4, Note_e4, Note_f4, Note_g4, Note_a4, Note_c5, Note_b4, Note_f5, Note_c6, Note_c5, Note_d5, Note_eb5, Note_f5, Note_g5, Note_a5, Note_bb5, Note_a5, Note_g5, Note_f5, Note_e5, Note_d5, Note_c5, Note_b4, Note_a4, Note_g5, Note_a5, Note_b5, Note_c6,  Note_b5, Note_a5, Note_g5, Note_b5, Note_c6, Note_d6, Note_e6, Note_d6, Note_c6, Note_b5, Note_d6, Note_f5, Note_d6, Note_a5, Note_d6, Note_a5, Note_c6, Note_d5,
};

Compiles ok for me with IDE 1.6.9
R is in a different position, I thought it was a typo when I was adding commas, I don't know from where so I stuck it at the beginning.
R is representing a rest and it's in the right spot. It corrolates with the rest in the piano piece.

SarahBethC

I got it to work, but it's not playing all of the notes. Still working.

SarahBethC

Ladies and Gents, it is now officially working!!!!

DocStein99


SarahBethC

Now, I am trying to add in anbother strain of notes, however, I cannot imput int melody[] twice....any suggestions???

DocStein99

Call it melody2[]

SarahBethC

Call it melody2[]
I did that but I need them to play atthe same time....

Go Up