I understand the principles of how to use " # include <filename.h> " to link to an external .h file where coded functions or subroutines can be referenced.
By example to use the RTClib library use #include <RTClib.h> & then ensure the RTClib library folder is accessable under the arduino library folder. The RTClib folder then contains text readable files of type .h and .CPP and also a file keywords.txt and a sub folder of example codes.
My question is: could I have a library folder with just a text file that will have the .h suffix and dump my common subroutines into that file, I intend that these lines of code will just be extracted from my top level .ino file OR must I use subroutines in the .h file that calls up further code in the .CPP file ?
I've not found a specific tutorial on librarys under the arduino.cc page.
Yes you can do that but there is a danger if you use the .h file in multiple places (multiple files) then you will get duplicate symbols.
@Nick,
don't the scope rules apply?
and where they don't the #ifdef construction takes care of redeclaration?
redeclaration is indeed fixed by the include guards. The problem is that, since the header file is pasted right into multiple compiled files, two files both declare the same functions, so the linker doesn't know which one to use.
If a.cpp and b.cpp both include foo.h and foo.h has an implementation (not just a function prototype) for function bar, then the linker will complain about duplicate implementations of bar.
But if you move the implementation into a .cpp file, the .cpp file is only compiled once, and this won't be a problem.