I'm trying to create Arduino buzzer controller, to play music, but when I was defining H (half) for a duration of notes, it is giving me errors
sketch_jan30g:24:11: error: expected '}' before numeric constant
#define H 2*Q //half 2/4
^
C:\Users\koumakpet\AppData\Local\Temp\arduino_modified_sketch_955882\sketch_jan30g.ino:49:3: note: in expansion of macro 'H'
H+Q, Q, Q
^
sketch_jan30g:24:11: error: expected ',' or ';' before numeric constant
#define H 2*Q //half 2/4
^
C:\Users\koumakpet\AppData\Local\Temp\arduino_modified_sketch_955882\sketch_jan30g.ino:49:3: note: in expansion of macro 'H'
H+Q, Q, Q
^
sketch_jan30g:57:1: error: expected declaration before '}' token
};
^
exit status 1 expected '}' before numeric constant
I'm not sure, what is the mistake, code:
//*****************************************
#define B3 247
#define C4 262 //Defining note frequency
#define D4 294
#define E4 330
#define F4 349
#define G4 392
#define LA4 440
#define B4 494
#define Bb4 466
#define C5 523
#define D5 587
#define E5 659
#define F5 698
#define G5 784
#define LA5 880
#define B5 988
// DURATION OF THE NOTES
#define BPM 120 // you can change this value changing all the others
#define H 2*Q //half 2/4
#define Q 60000/BPM //quarter 1/4
#define E Q/2 //eighth 1/8
#define S Q/4 // sixteenth 1/16
#define W 4*Q // whole 4/4
//*****************************************
int notes[] = { //Note of the song, 0 is a rest/pulse
E4, C5, E5,
D5, F5, G5,
E5,
0, Bb4, F5, G5, LA5, F5,
E5, E5, C5, E5,
B4, 0,
E4, C5, E5,
D5, F5, G5,
E5,
0, Bb4, F5, G5, LA5, F5,
E5, E5, C5, E5,
B4, 0,
0
};
//*****************************************
int duration[] = {
H+Q, Q, Q
H+Q, Q, Q
W,
Q, Q, Q, Q, Q, Q,
H, H
H, Q, Q, Q,
W+H+Q, Q,
3*W
};
void setup() {
for (int i=0;i<203;i++){ //203 is the total number of music notes in the song
int wait = duration[i];
tone(buzzer,notes[i],wait); //tone(pin,frequency,duration)
delay(wait);} //delay is used so it doesn't go to the next loop before tone is finished playing
//You can click reset on Arduino to replay the song
}
void loop() {
}
EDIT: Note that I've tried replacing the positions of H and Q (because H is dependant on Q), the error was still there.