I am working on an Arduino project (making it a music player) and I have an error that I cannot figure out, even after a solid google session. Here is my code, I stripped non-important stuff.
I have 5 songs witch I want to cycle through
//#define notes
int songLength;
int melody;
int noteDurations;
unsigned long verschil = 0;
int thisNote = 0;
double speed;
int song = 1;
void song1(melody, noteDurations) {
memset(melody, 0, sizeof(melody));
memset(noteDurations, 0, sizeof(noteDurations));
songLength = 112;
melody[] = {
//the notes of the song
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
noteDurations[] = {
//the noteduration of the song
};
}
void song2(melody, noteDurations) {
memset(melody, 0, sizeof(melody));
memset(noteDurations, 0, sizeof(noteDurations));
songLength = 72;
melody[] = {
//the notes of the song
};
noteDurations[] = {
//the noteduration of the song
};
}
void song3(melody, noteDurations) {
memset(melody, 0, sizeof(melody));
memset(noteDurations, 0, sizeof(noteDurations));
songLength = 24;
melody[] = {
//the notes of the song
};
noteDurations[] = {
//the noteduration of the song
};
}
void song4(melody, noteDurations) {
memset(melody, 0, sizeof(melody));
memset(noteDurations, 0, sizeof(noteDurations));
songLength = 105;
melody[] = {
//the notes of the song
};
noteDurations[] = {
//the noteduration of the song};
}
void song5(melody, noteDurations) {
memset(melody, 0, sizeof(melody));
memset(noteDurations, 0, sizeof(noteDurations));
songLength = 80;
melody[] = {
//the notes of the song
};
// note durations: 4 = quarter note, 8 = eighth note, etc
noteDurations[] = {
//the noteduration of the song
};
}
void loadSong(song) {
if (song == 1) {
song1(melody, noteDurations);
}
if (song == 2) {
song2(melody, noteDurations);
}
if (song == 3) {
song3(melody, noteDurations);
}
if (song == 4) {
song4(melody, noteDurations);
}
if (song == 5) {
song5(melody, noteDurations);
song = 1;
} else {
song++;
}
}
void setup()
{
//setup
loadSong(song);
}
void loop() {
//playing the song
int noteDuration = 750 / noteDurations[thisNote];
tone(13, melody[thisNote], noteDuration);
int sensorValue = analogRead(A1);
//Serial.println(sensorValue);
if (sensorValue < 200) {
speed = 0;
} else {
speed = sensorValue * 0.001;
}
speed = speed + 0.2;
Serial.println(speed);
int pauseBetweenNotes = noteDuration * 1.30 * speed;
delay(pauseBetweenNotes);
noTone(13);
if (thisNote < songLenght) {
thisNote++;
} else {
thisNote = 0;
loadSong(song);
}
}
I get the following error at each song function I declare and define:
101:12: error: variable or field 'song1' declared void
169:12: error: variable or field 'song2' declared void
195:12: error: variable or field 'song3' declared void
214:12: error: variable or field 'song4' declared void
251:12: error: variable or field 'song5' declared void
I really don't know what to do know, all the answers I find on google are related when calling the function. but the error occurs on the line where I make the function and it's contents.
I hope someone can help me out
ps. I am also getting some other errors but they are not relevant to this question, I will show them anyways
287:19: error: variable or field 'loadSong' declared void
In function 'void setup()':
325:3: error: 'loadSong' was not declared in this scope
325:3: note: suggested alternative: 'long'
In function 'void loop()':
329:50: error: invalid types 'int[int]' for array subscript
330:27: error: invalid types 'int[int]' for array subscript
345:18: error: 'songLenght' was not declared in this scope
345:18: note: suggested alternative: 'songLength'
349:5: error: 'loadSong' was not declared in this scope
349:5: note: suggested alternative: 'long'