Tone.h not found

Hi everybody,

I have a question.
When compiling my new project I get an error on a library, Tone.h. It says every time I try: No such file or directory. But the file is in the directory it is looking for… See screenshot.

I can also open Tone.h in the Arduino program through Sketch-Add File.

Can anybody help me?

Thanks,

Anna

If Tone.h is in the same folder as your sketch file then try

#include "Tone.h"

Thanks for your answer,
I tried that but it didn't work.
Do you or anybody else have another option?

Thanks,

Anna

Do you or anybody else have another option?

I have another question. Do you actually have a Tone.h file anywhere on your computer?

POST YOUR CODE, not a stupid picture.

Yes, I downloaded Tone.h on my pc.
See the screenshots below

Oh and here is the whole code:
// Gebruikt met vriendelijke toestemming van Abdullah Alhazmy www.Alhazmy13.net
#include <Tone.h>
Tone speakerpin;
int starttune = {NOTE_C4, NOTE_F4, NOTE_C4, NOTE_F4, NOTE_C4,
NOTE_F4, NOTE_C4, NOTE_F4, NOTE_G4, NOTE_F4,
NOTE_E4, NOTE_F4, NOTE_G4
};
int duration2 = {100, 200, 100, 200, 100, 400, 100, 100, 100, 100,
200, 100, 500
};
int note = {NOTE_C4, NOTE_C4, NOTE_G4, NOTE_C5, NOTE_G4, NOTE_C5};
int duration = {100, 100, 100, 300, 100, 300};
boolean button = {2, 3, 4, 5}; // Pennen aangesloten op input van drukknoppen
boolean ledpin = {8, 9, 10, 11}; // Pennen aangesloten op ledjes
int turn = 0; // Tellen van aantal beurten
int buttonstate = 0; // Controleer status van drukknop
int randomArray[100]; // Bereik dat tot 100 inputs op kan slaan
int inputArray[100];
void setup() {
Serial.begin(9600);
speakerpin.begin(12); // Pen aangesloten op piëzo zoemer
for (int x = 0; x < 4; x++) {
pinMode(ledpin, OUTPUT); // Stel led pennen in als output
}
for (int x = 0; x < 4; x++) {
pinMode(button, INPUT); // Stel drukknop pennen in als inputs
digitalWrite(button, HIGH); // Intern omhoogtrekken inschakelen;
// drukknoppen starten in hoge positie
// omgekeerde logica
}
// Meer “willekeur” genereren met randomArray voor de output
// functie zodat het patroon elke keer anders is
randomSeed(analogRead(0));
for (int thisNote = 0; thisNote < 13; thisNote ++) {
speakerpin.play(starttune[thisNote]); // Speel de volgende noot af
if (thisNote == 0 || thisNote == 2 || thisNote == 4 ||
thisNote == 6) { // Houd de noot vast
digitalWrite(ledpin[0], HIGH);
}
if (thisNote == 1 || thisNote == 3 || thisNote == 5 ||
thisNote == 7 || thisNote == 9 || thisNote == 11) {
digitalWrite(ledpin[1], HIGH);
}
if (thisNote == 8 || thisNote == 12) {
digitalWrite(ledpin[2], HIGH);
}
if (thisNote == 10) {
digitalWrite(ledpin[3], HIGH);
}
delay(duration2[thisNote]);
speakerpin.stop(); // Stop voor de volgende noot
digitalWrite(ledpin[0], LOW);
digitalWrite(ledpin[1], LOW);
digitalWrite(ledpin[2], LOW);
digitalWrite(ledpin[3], LOW);
delay(25);
}
delay(1000);
}
void loop() {
// Genereer het bereik dat de speler na moet bootsen
for (int y = 0; y <= 99; y++) {
digitalWrite(ledpin[0], HIGH);
digitalWrite(ledpin[1], HIGH);
digitalWrite(ledpin[2], HIGH);
digitalWrite(ledpin[3], HIGH);
// Speel de volgende noot af
for (int thisNote = 0; thisNote < 6; thisNote ++) {
speakerpin.play(note[thisNote]); // Houd de noot vast
delay(duration[thisNote]); // Stop voor de volgende noot
speakerpin.stop();
delay(25);
}
digitalWrite(ledpin[0], LOW);
digitalWrite(ledpin[1], LOW);
digitalWrite(ledpin[2], LOW);
digitalWrite(ledpin[3], LOW);
delay(1000);
// Beperkt door de “beurt” variabele
for (int y = turn; y <= turn; y++) {
Serial.println("");
Serial.print(“Turn: “);
Serial.print(y);
Serial.println(””);
randomArray[y] = random(1, 5); // Wijs een willekeurig getal toe (1-4)
// Zed ledjes in willekeurige volgorde aan
for (int x = 0; x <= turn; x++) {
Serial.print(randomArray);
for (int y = 0; y < 4; y++) {
if (randomArray == 1 && ledpin[y] == 8) {
digitalWrite(ledpin[y], HIGH);
speakerpin.play(NOTE_G3, 100);
delay(400);
digitalWrite(ledpin[y], LOW);
delay(100);
}
if (randomArray == 2 && ledpin[y] == 9) {
digitalWrite(ledpin[y], HIGH);
speakerpin.play(NOTE_A3, 100);
delay(400);
digitalWrite(ledpin[y], LOW);
delay(100);
}
if (randomArray == 3 && ledpin[y] == 10) {
digitalWrite(ledpin[y], HIGH);
speakerpin.play(NOTE_B3, 100);
delay(400);
digitalWrite(ledpin[y], LOW);
delay(100);
}
if (randomArray == 4 && ledpin[y] == 11) {
digitalWrite(ledpin[y], HIGH);
speakerpin.play(NOTE_C4, 100);
delay(400);
digitalWrite(ledpin[y], LOW);
delay(100);
}
}
}
}
input();
}
}
// Controleer of de input overeenkomt met het patroon
void input() {
for (int x = 0; x <= turn;) {
for (int y = 0; y < 4; y++) {
buttonstate = digitalRead(button[y]); // Controleer of knop wordt ingedrukt
if (buttonstate == LOW && button[y] == 2) {
digitalWrite(ledpin[0], HIGH);
speakerpin.play(NOTE_G3, 100);
delay(200);
digitalWrite(ledpin[0], LOW);
inputArray = 1;
delay(250);
Serial.print(" “);
Serial.print(1);
// Controleer of input van gebruiker overeenkomt met gegenereerd patroon
if (inputArray != randomArray) {
fail(); // Zo niet, dan wordt functie “mislukt” aangeroepen
}
x++;
}
if (buttonstate == LOW && button[y] == 3) {
digitalWrite(ledpin[1], HIGH);
speakerpin.play(NOTE_A3, 100);
delay(200);
digitalWrite(ledpin[1], LOW);
inputArray = 2;
delay(250);
Serial.print(” “);
Serial.print(2);
if (inputArray != randomArray) {
fail();
}
x++;
}
if (buttonstate == LOW && button[y] == 4) {
digitalWrite(ledpin[2], HIGH);
speakerpin.play(NOTE_B3, 100);
delay(200);
digitalWrite(ledpin[2], LOW);
inputArray = 3;
delay(250);
Serial.print(” “);
Serial.print(3);
if (inputArray != randomArray) {
fail();
}
x++;
}
if (buttonstate == LOW && button[y] == 5) {
digitalWrite(ledpin[3], HIGH);
speakerpin.play(NOTE_C4, 100);
delay(200);
digitalWrite(ledpin[3], LOW);
inputArray = 4;
delay(250);
Serial.print(” ");
Serial.print(4);
if (inputArray != randomArray) {
fail();
}
x++;
}
}
}
delay(500);
turn++; // Verhoog aantal beurten
}
// Functie die gebruikt wordt als speler er niet in slaagt volgorde na te bootsen
void fail() {
for (int y = 0; y <= 2; y++) { // Knipper met lampjes om aan te geven dat het mislukt is
digitalWrite(ledpin[0], HIGH);
digitalWrite(ledpin[1], HIGH);
digitalWrite(ledpin[2], HIGH);
digitalWrite(ledpin[3], HIGH);
speakerpin.play(NOTE_G3, 300);
delay(200);
digitalWrite(ledpin[0], LOW);
digitalWrite(ledpin[1], LOW);
digitalWrite(ledpin[2], LOW);
digitalWrite(ledpin[3], LOW);
speakerpin.play(NOTE_C3, 300);
delay(200);
}
delay(500);
turn = -1; // Reset waarde “beurten” om spel opnieuw te starten
}

I am 100% certain that your code does NOT look like that. There are stickies at the top of the forum. Read them BEFORE posting code again.

Your error3 picture shows two files in the same directory. One has no extension shown. One does. I KNOW that the ino file does have an extension. So, I suspect that the other file is actually called Tone.h.h.

Why those idiots in Redmond think that hiding extensions is a good idea is a complete mystery. Turn that option OFF and leave it off.

I put it off and behind the first file I get indeed .ino,
but Tone.h keeps Tone.h and not Tone.h.h and the error keeps also..

You need to make this change:

UKHeliBob:
If Tone.h is in the same folder as your sketch file then try

#include "Tone.h"

Quotes around Tone.h, not angle brackets.

If I do that I get this error:

Arduino: 1.8.3 (Windows 10), Board:"Arduino/Genuino Uno"

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '2' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

boolean button = {2, 3, 4, 5}; // Pennen aangesloten op input van drukknoppen

^

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '3' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '4' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:13:31: warning: narrowing conversion of '5' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '8' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

boolean ledpin = {8, 9, 10, 11}; // Pennen aangesloten op ledjes

^

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '9' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '10' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game\Project_8_Memory_game.ino:14:33: warning: narrowing conversion of '11' from 'int' to 'boolean {aka bool}' inside { } [-Wnarrowing]

C:\Users\GEBRUI~1\AppData\Local\Temp\cc50oNzf.ltrans0.ltrans.o: In function `fail()':

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:198: undefined reference to `Tone::play(unsigned int, unsigned long)'

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:204: undefined reference to `Tone::play(unsigned int, unsigned long)'

C:\Users\GEBRUI~1\AppData\Local\Temp\cc50oNzf.ltrans0.ltrans.o: In function `setup':

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:21: undefined reference to `Tone::begin(unsigned char)'

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:35: undefined reference to `Tone::play(unsigned int, unsigned long)'

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:51: undefined reference to `Tone::stop()'

C:\Users\GEBRUI~1\AppData\Local\Temp\cc50oNzf.ltrans0.ltrans.o: In function `loop':

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:69: undefined reference to `Tone::play(unsigned int, unsigned long)'

C:\Users\Gebruiker\Documents\Arduino\libraries\Project_8_Geheugen_spelletje\Project_8_Memory_game/Project_8_Memory_game.ino:71: undefined reference to `Tone::stop()'

collect2.exe: error: ld returned 1 exit status

exit status 1
Fout bij het compileren van board Arduino/Genuino Uno

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

 boolean button[] = {2, 3, 4, 5}; // Pennen aangesloten op input van drukknoppen

Why are you using boolean (true or false) to hold pin numbers? byte is the same size and is more appropriate.

Where did you get that Tone.h file? What, exactly, is in it?

Where did you get the Tone.h file and is there a Tone.cpp file to go with it ?

I get it from the site www.visualsteps.nl/arduinohandboek/projectbestanden.php and I have also the Tone.cpp file from the same site.

Where have you put Tone.cpp on your PC ?

Files > Arduino > libraries > libraries > Tone

Annaaa:
Files > Arduino > libraries > libraries > Tone

You MUST put the Tone.cpp file in the same folder as the Tone.h file. There should NOT be a libraries folder in the libraries folder.

I put Tone.cpp also in the sketch and now I have no error :slight_smile:

What made you decide to put Tone.h in the sketch folder in the first place ?