#include "Motor.h"
void setup() {
Serial.begin(57600);
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
I keep getting
"fatal error: Motor.h: No such file or directory #include "Motor.h"
Motor.h is located in the following directory
MyCode (directory)
-> MyCode (directory)
--> MyCode.ino
-> libraries (directory)
--> Motor (directory)
---> Motor.h
---> Motor.cpp
I've looked around the forums and this is what everyone is suggesting but It is simply not working
You can't just put the library in any random folder named libraries. The Arduino IDE looks in a few specific places for libraries. The place where user installed libraries are supposed to be is {sketchbook folder}/libraries. You can set the location of the sketchbook folder to anything that is convenient in the IDE preferences. If for some reason that doesn't suit what you're trying to do then please explain further and I can help you out.
I wasn't aware that libraries are suppose to be located in {sketchbook folder}/libraries.
I thought that if I have a project directory
I could simply create a "libraries" directory within the project directory and put all my include files in there. My understanding was that since libraries was in the "current working directory of my sketch" it would be detected.
That way if I need to hand over the project code to someone else I would just have to zip up that project directory.
Usually I think it's better to install libraries to a common location so that all your projects can share the same library but in the case of wanting a project to be self contained it definitely makes sense to put it all in the project folder. This is possible but you have to make a couple of changes:
Unfortunately some libraries use incorrect include syntax, which still works when the library is installed in one of the standard libraries folders but doesn't when you try to bundle a library with a sketch. An example is if Motor.cpp has the line:
#include <Motor.h>
you need to change that to:
#include "Motor.h"
The quotes indicate that the current directory should be checked for the file first before looking in the other include folders. The angle brackets syntax will not cause the current folder to be checked. You need to remember to use the quotes include syntax in any sketch that's including a bundled library.
You also have the option of just putting the library source files directly in the sketch folder but that clutters up both the folder and the IDE because those files will appear as tabs when the sketch is opened. If the user is unlikely to have the need to edit those files it's much better to put them in their own folder.