Pages: [1]   Go Down
Author Topic: .cpp and .h file locations  (Read 1314 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 8
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on a wall detecting bug bot out of the Arduino Robotics book. It basically closes one of five switches to tell it that it has hit an object Got it working with no problem.  As I am still learning, I thought I would put a speaker on it and make it play a sound when one of the switches closed. The file I'm trying to incorporate into my (working) bug bot sketch is the tone example located in the Arduino library, and it uses the 'pitches.h' file. So I put "#include pitches.h" right under the "#include servo.h statement.  I then compile to make sure it's finding the pitches.h file, and I get the following, "Bug_bot_Music.cpp:12:21: error: pitches.h: No such file or directory"

Now my questions. There is no bug_bot_music.cpp file.  Matter of fact, the original sketch was copied and pasted out of a pdf file, so I don't have a .cpp with this sketch, as far as I know. Am I wrong to assume that a sketch doesn't have to have a .cpp file to compile correctly.  And secondly, the pitches.h file is presently located in the library/tone directory, but evidently this new sketch is not finding it. So.....what am I doing wrong and where should I locate my files so the compiler finds them correctly.

As I said, I'm new, so be kind and just tolerate my ignorance.
Logged

Offline Offline
Edison Member
*
Karma: 17
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You'll want to have the pitches.h file in the same directory as your .pde file. The IDE creates a .cpp file out of your .pde file after it adds some things, the location of which can be found when holding shift while compiling (but not uploading).

Also, you'll want to use this syntax:
Code:
#include "pitches.h"
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You may need to click on the "new tab" icon (top RH corner in the IDE) and make pitches.h the file name. Then paste the contents into the window that appears. Otherwise it may still not know about the file.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 61
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now my questions. There is no bug_bot_music.cpp file.  Matter of fact, the original sketch was copied and pasted out of a pdf file, so I don't have a .cpp with this sketch, as far as I know. Am I wrong to assume that a sketch doesn't have to have a .cpp file to compile correctly.  And secondly, the pitches.h file is presently located in the library/tone directory, but evidently this new sketch is not finding it. So.....what am I doing wrong and where should I locate my files so the compiler finds them correctly.

What is the name of your sketch file, including extension?

Then, pitches.h (and pitches.c or pitches.cpp, if existing), need to be in the 'libraries/tone' directory, 'not library/tone' (see the plural?), inside your sketchbook dir.

And, you need to restart the IDE after you have placed a new lib into the libraries directory.
Logged

Pages: [1]   Go Up
Jump to: