1

I have some small functions to format numbers. I move them to a new file and I would like to import it to my proyect.

I can't find how to do it without defining a class (maybe it's the only way). I would like to import like JavaScript, PHP or other languages: just using the import word or something similar.

I know how to import libraries. Example:

#include <OneWire.h>
#include <DallasTemperature.h>

1 Answer 1

1

If the file is in your sketch folder then you use this syntax:

#include "foo.h"

All source files in the root of the sketch folder are shown as tabs in the Arduino IDE. In some cases that might not be desirable. If so, you can put the file in the src subfolder of your sketch folder and use this syntax:

#include "src/foo.h"

Or you might want to group files together into separate subfolders:

#include "src/foo/foo.h"

If you want to access the file from multiple sketches then you should turn it into a library and use this syntax:

#include <foo.h>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.