Error compiling: "Exit status 1, 'variable' was not declared in this scope"

I’m trying to make a music player with arduino and a buzzer. I already made a few songs by typing each frequency and delay in a function, but I got a little tired. I figured I’d make a function for each note with the frequency and duration. I did this and put them all together in a function for the song, but now I’m getting the error code “Exit status 1, ‘variable’ was not declared in this scope”

#include <TonePlayer.h>

int tempo = 2000;

void setup() {
  // put your setup code here, to run once:
 
 }

void loop() {
  miiTheme();

}





void miiTheme() {
//1
  f4sharptone (4);
  a4tone (8);
  c4sharptone (4);
  a4tone (4);
  f4sharptone (8); 
//2
  d4tone (8);
  d4tone (8);
  d4tone (8);
  toneBreak (8);
  toneBreak (4);
  toneBreak (8);
  c4sharptone (8);
//3
  d4tone (8);
  f4sharptone (8);
  a4tone (8);
  c4sharptone (4);
  a4tone (4);
  f4sharptone (8);
//4
  e5tone (4);
  d5sharptone (8);
  d5tone (8);
  toneBreak (8);
  toneBreak (4);
}

/*
tone1.tone (293);
delay(300);
tone1.noTone ();
delay(50);
*/

void toneBreak (int lenght){
  tone1.noTone ();
  delay(tempo/length);
}

void c4tone (int lenght){
  tone1.tone (261);
  delay(tempo/length);
  tone1.noTone ();
}

void d4tone (int lenght){
  tone1.tone (293);
  delay(tempo/length);
  tone1.noTone ();
}

void d5tone (int lenght){
  tone1.tone (587);
  delay(tempo/length);
  tone1.noTone ();
}


void e4tone (int lenght){
  tone1.tone (329);
  delay(tempo/length);
  tone1.noTone ();
}

void e5tone (int lenght){
  tone1.tone (659);
  delay(tempo/length);
  tone1.noTone ();
}


void f4tone (int lenght){
  tone1.tone (349);
  delay(tempo/length);
  tone1.noTone ();
}

void g4tone (int lenght){
  tone1.tone (392);
  delay(tempo/length);
  tone1.noTone ();
}

void a4tone (int lenght){
  tone1.tone (440);
  delay(tempo/length);
  tone1.noTone ();
}

void h4tone (int lenght){
  tone1.tone (493);
  delay(tempo/length);
  tone1.noTone ();
}



void c4sharptone (int lenght){
  tone1.tone (277);
  delay(tempo/length);
  tone1.noTone ();
}

void d4sharptone (int lenght){
  tone1.tone (311);
  delay(tempo/length);
  tone1.noTone ();
}

void d5sharptone (int lenght){
  tone1.tone (622);
  delay(tempo/length);
  tone1.noTone ();
}


void f4sharptone (int lenght){
  tone1.tone (369);
  delay(tempo/length);
  tone1.noTone ();
}

void g4sharptone (int lenght){
  tone1.tone (415);
  delay(tempo/length);
  tone1.noTone ();
}

void a4sharptone (int lenght){
  tone1.tone (466);
  delay(tempo/length);
  tone1.noTone ();
}

this is only the music part of my code, and due to something in the other part I can’t use tone() and had to import another libary I know works.

on your entire program, use auto-format. Then, check parenthesis and brackets. It's often a missing brace.

if not a missing brace, it could be that you are using a automatic variable out of scope. For example if you declare and initialize a variable in one function or inside a case, or for loop etc. and then try to use that variable name outside of that function, case or for loop...

lenght is not the same as length.

It helps if you post the error message(s)

TheMemberFormerlyKnownAsAWOL:
lenght is not the same as length.

It helps if you post the error message(s)

Error cut and pasted. Lol

TheMemberFormerlyKnownAsAWOL:
lenght is not the same as length.

It helps if you post the error message(s)

Perehama:
on your entire program, use auto-format. Then, check parenthesis and brackets. It’s often a missing brace.

I did both of these, but I still get the same errors. This is my code now:

#include <TonePlayer.h>

int tempo = 2000;

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  miiTheme();

}





void miiTheme() {
  //1
  f4sharptone (4);
  a4tone (8);
  c4sharptone (4);
  a4tone (4);
  f4sharptone (8);
  //2
  d4tone (8);
  d4tone (8);
  d4tone (8);
  toneBreak (8);
  toneBreak (4);
  toneBreak (8);
  c4sharptone (8);
  //3
  d4tone (8);
  f4sharptone (8);
  a4tone (8);
  c4sharptone (4);
  a4tone (4);
  f4sharptone (8);
  //4
  e5tone (4);
  d5sharptone (8);
  d5tone (8);
  toneBreak (8);
  toneBreak (4);
}

/*
  tone1.tone (293);
  delay(300);
  tone1.noTone ();
  delay(50);
*/

void toneBreak (int dura ) {
  tone1.noTone ();
  delay(tempo / dura);
}

void c4tone (int dura) {
  tone1.tone (261);
  delay(tempo / dura);
  tone1.noTone ();
}

void d4tone (int dura) {
  tone1.tone (293);
  delay(tempo / dura);
  tone1.noTone ();
}

void d5tone (int dura) {
  tone1.tone (587);
  delay(tempo / dura);
  tone1.noTone ();
}


void e4tone (int dura) {
  tone1.tone (329);
  delay(tempo / dura);
  tone1.noTone ();
}

void e5tone (int dura) {
  tone1.tone (659);
  delay(tempo / dura);
  tone1.noTone ();
}


void f4tone (int dura) {
  tone1.tone (349);
  delay(tempo / dura);
  tone1.noTone ();
}

void g4tone (int dura) {
  tone1.tone (392);
  delay(tempo / dura);
  tone1.noTone ();
}

void a4tone (int dura) {
  tone1.tone (440);
  delay(tempo / dura);
  tone1.noTone ();
}

void h4tone (int dura) {
  tone1.tone (493);
  delay(tempo / dura);
  tone1.noTone ();
}



void c4sharptone (int dura) {
  tone1.tone (277);
  delay(tempo / dura);
  tone1.noTone ();
}

void d4sharptone (int dura) {
  tone1.tone (311);
  delay(tempo / dura);
  tone1.noTone ();
}

void d5sharptone (int dura) {
  tone1.tone (622);
  delay(tempo / dura);
  tone1.noTone ();
}


void f4sharptone (int dura) {
  tone1.tone (369);
  delay(tempo / dura);
  tone1.noTone ();
}

void g4sharptone (int dura) {
  tone1.tone (415);
  delay(tempo / dura);
  tone1.noTone ();
}

void a4sharptone (int dura) {
  xzzx  tone1.tone (466);
  delay(tempo / dura);
  tone1.noTone ();
}

(I changed length to dura)

but I still get the same errors.

But you decided not to share the error messages.

Good luck with that approach

TheMemberFormerlyKnownAsAWOL:
But you decided not to share the error messages.

Good luck with that approach

The error message was to long for me to share the entire thing, but the last part of it was:

C:\Users\Mats Bjonnes\Documents\Arduino\spilled_se\spilled_se.ino:147:3: note: suggested alternative: 'tone'
   tone1.tone(466);
   ^~~~~
   tone
Using library TonePlayer in folder: C:\Users\Mats Bjonnes\Documents\Arduino\libraries\TonePlayer (legacy)
exit status 1
'tone1' was not declared in this scope

That’s not the same error message.
The clue is that it doesn’t contain the same words.

So, where is tone1 declared?

TheMemberFormerlyKnownAsAWOL:
That's not the same error message.
The clue is that it doesn't contain the same words.

So, where is tone1 declared?

It's imported from the TonePlayer library

nuddel69:
It's imported from the TonePlayer library

What makes you think that? Is it in your TonePlayer.h? Can you point us to the source for your
version of TonePlayer?

MarkT:
What makes you think that? Is it in your TonePlayer.h? Can you point us to the source for your
version of TonePlayer?

I reckon it's from the TonePlayer library as I used it in another project and it worked fine. It is also used in the example on the download page here: Gammon Forum : Electronics : Microprocessors : Timers and counters

nuddel69:
I reckon it's from the TonePlayer library as I used it in another project and it worked fine. It is also used in the example on the download page here: Gammon Forum : Electronics : Microprocessors : Timers and counters

So, where is this line in your code?