Best way to make a project with multiple files

Ted Tedson picture Ted Tedson · Jun 21, 2014 · Viewed 14.5k times · Source

I am developing Arduino based system that will enlarge over time. At the moment it has only the humidity and temperature read functionality. But soon a door control, sound recording and gsm web client support will be added. I want all these to be included as libraries and used in the main part. I'm thinking of one ino file that includes all other modules and calls their functions. My question is what is the best and most clean way to do it?

Answer

mpflaga picture mpflaga · Jun 21, 2014

I recommend sticking with libraries and library directories with examples. A library for each component to be interfaced with. This will help in many ways. Such as debugging and reuse.

C:\Users\myself\Google Drive\Arduino\libraries\componentX\componentX.h
C:\Users\myself\Google Drive\Arduino\libraries\componentX\componentX.cpp
C:\Users\myself\Google Drive\Arduino\libraries\componentY\componentY.h
C:\Users\myself\Google Drive\Arduino\libraries\componentY\componentY.cpp
etc...

This keeps it modular and compartmentalized.

Notice I have changed the Arduino's IDE preferences to Google Drive. (Cloud backup and portability)

Then rather than one BIG INO file in your sketch folder

C:\Users\myself\Google Drive\Arduino\somethingBIG\somethingBIG.ino

implement INO files in the

C:\Users\mflaga\Google Drive\Arduino\libraries\component\examples.

directories. This makes it quick to publish the components on GITHUB or Google Drive to share between systems.

Then you can have a sketch file that ties all the components together into your main project.

C:\Users\myself\Google Drive\Arduino\somethingTOPlevel\somethingTOPlevel.ino