I'd like to organize my code by moving a large array into another file. Can I import the array from another .ino file?
If so, what is the syntax for this?
I'd like to organize my code by moving a large array into another file. Can I import the array from another .ino file?
If so, what is the syntax for this?
Hi @soggybag
I think it could be like this:
Name the new file xxxxx.h
and include xxxxx.h at the beginning of your code.
But both mySketch.ino and xxxxx.h files need to be in the same folder.
RV mineirin
Note that if xxxxx.h is in the same folder as the .ino file then the syntax to #include it is
#include "xxxxx.h"
rather than
#include <xxxxx.h>
use "extern"
it's bad practice to put code or data definitions in a .h file which may be included in multiple other .ino/.cpp files which would then result in duplicated symbols
i think it's a good idea to put large data definitions in a separate .cpp file. a corresponding .h file containing a declaration would also be created -- extern int *myArray;
one drawback is the implicit size of the data is less convenient (i.e. sizeof()). i've captured size information in variables which are also then made externally accessible.
there are several advantages to isolating the data
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.