Calling functions from another file

I coded some functions for another sketch. I now want to use those functions in another project without having to include the whole code. Can't I use #INCLUDE? Im not clear in the syntax to use it or where the file should be saved.
Thanks its been many many years since I studied programing.

#INCLUDE <myCountDownsdkd.ino> // the file that hold the function countDown()

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

void loop() {
countDown();
}

Can't I use #INCLUDE? Im not clear in the syntax to use it or where the file should be saved.

It would have been faster to test the code than to write this post. Try it yourself.

If the other ino file is in the same directory as the one you want to include it in, there is nothing you need to do. The IDE combines all ino files into one cpp file for compiling.

If the other ino file lives somewhere else, you need to include the full path.

Of course, if the other ino file includes a setup() and loop() function, you can't do what you want.

after reading some more I think what I want to do is create a library and then include that in future sketches?
Sorry just getting my feet wet after a long time.

You can include a .h or a .cpp file, that would be clearer than the .ino.

A .cpp without objects (just functions) should also work as long as you have a separate header file with function prototypes so that the file ordering doesn't get in the way. Haven't tried this, but it should work.

Move the functions to a .cpp file. Put their prototypes in a .h file.

Put both files into a folder and put that in the libraries folder. Restart the IDE. Then include the .h file and it should all work.

eg. Make foo.cpp, foo.h, put both into "foo" directory. Put "foo" directory under "libraries" under your sketches folder. Then:

#include <foo.h>

Nick,
thank you for the help. That's the first time i got my C functions working :).

I also want to point out that the there is a more sane way to get this functionality to work. I came across this post What is the effect of extern "C" in C++? - Stack Overflow
.Now, my code looks like this :

//test.ino

#ifdef __cplusplus
extern "C"{
	#endif
	#include <myCLib.h>
	#ifdef __cplusplus
} ;
#endif

the library is a general C library i put under libraries folder and have sane file extensions - .h and .c
:slight_smile: