So you have an Arduino program (or sketch) and it’s getting a bit cumbersome and messy. Now could be the time to start breaking your program up into smaller more manageable chunks.

A basic solution (see code below) for breaking the program into more managable chunks is to put the common variables declarations into a shared file that gets included into each program file (shared.h here) and the implementation into a source file (Shared.cpp here). Use #include “Shared.h” to get access to the globals for each source file (.cpp or .ino) that needs them.




A more complex solution is to use classes. Adafruit have a good example where they transfer a basic program into a class.

You might also want to move to a more powerful integrated development invironment (IDE) such as Visual Studio (with Visual Micro plugin) or Eclipse and start useing some more advanced approaches to coding.

Recent Posts

Leave a Comment

Start typing and press Enter to search