For an upcoming Arduino project, I thought it would be handy to define an array of structs as a header file to include in the sketch. Searching for "struct array arduino" turned out to be pretty helpful.
In the first result forum post, the struct is populated in the loop() function.
For the header file, I found that the struct array still needs to be populated in a function.
So I created the following function in the header file.
typedef struct{
double Lat;
double Long;
} RouteData;
#define ROUTEDATALENGTH 2
RouteData RouteArray[ROUTEDATALENGTH];
void DefineRouteArray(){
// For some reason, struct arrays need
// to be defined in a function.
RouteArray[0] = (RouteData) {-68.975363, -71.614769};
RouteArray[1] = (RouteData) {-69.852626, -75.018339};
}
Then I added the DefineRouteArray() function to the setup() function in the main Sketch, and was able to compile.
In the first result forum post, the struct is populated in the loop() function.
For the header file, I found that the struct array still needs to be populated in a function.
So I created the following function in the header file.
typedef struct{
double Lat;
double Long;
} RouteData;
#define ROUTEDATALENGTH 2
RouteData RouteArray[ROUTEDATALENGTH];
void DefineRouteArray(){
// For some reason, struct arrays need
// to be defined in a function.
RouteArray[0] = (RouteData) {-68.975363, -71.614769};
RouteArray[1] = (RouteData) {-69.852626, -75.018339};
}
Then I added the DefineRouteArray() function to the setup() function in the main Sketch, and was able to compile.