Blinkerton Labs
  • Blog
  • Projects
    • AutoBoat
    • Blinkly Blink
    • Wireless Temperature Monitor
  • Reference
    • PCB Design
  • About

Struct Array Definition in an Arduino Sketch Header File

7/22/2017

 
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.

    Author

    Mainly random electronics projects.  Sometimes other topics.

    Archives

    January 2020
    March 2019
    January 2019
    July 2017
    April 2016
    January 2015
    September 2014
    March 2014

    Categories

    All
    Arduino

    RSS Feed

Proudly powered by Weebly