I am trying to create a structure that I access from a .cpp library file and a .ino(new file ext for pde, created in arduino ide). The structure will have a few variables that I will need to set/get in the myfile.pde and the mylibraryfile.cpp files. Should I define the structure in another .h file, something like mystructure.h? I would like to initialize the structure in the mylibraryfile.cpp file. Currently, my files look like this. Can anyone provide assistance on how to do this?
the .h should contain the structure declaration,
the .cpp should contain the structures function definitions.
Your .ino file should create the object instance.
int DataFunc( void );
void DoStuff( MyStruct &m_Struct );
int MyStruct::DataFunc( void )
void DoStuff( MyStruct &m_Struct )
//Do Stuff with structure
//Create structure instance.
int i_Val = m_StructureVariable.Data();
DoStuff( m_StructureVariable );
Thanks for the info, but there is no way to create the object instance inside the mylibraryfile.cpp file and still access in the .ino file? I will have includes mylibraryfile.h in the .ino file. What is it a problem?
but there is no way to create the object instance inside the mylibraryfile.cpp file and still access in the .ino file?
Sure, there is. Create the instance in the .cpp file. You will need to tell the sketch that the structure is extern(al) to the sketch file, so there really isn't much advantage in initializing the structure in the cpp file.