I have been developing a couple of similar but different sketches for MEGA2560 over several years.
The two sketches are SCOO7 and NSX06 are quite large (52,500 and 45,600 bytes respectively) so I like to organise my sketches using tabs, like this for example for the NSX06 sketch:
NSX06 - main tab, with #defines, #includes, declarations etc but no code
AAsetup - setup()
ABloop - loop()
AT0250 - timed to run every 250ms
AT0500 - timed to run every 500ms
AT2000 - timed to run every 2s
AT5000 - timed to run every 5s
Celsius - temperature measurements
GPS - GPS handling
LCD - display handling
LOG - logging to microSD card
MENU - Menu of commands used when Serial monitor available
RPM - engine Revs Per Minute
Time - handling time from GPS and separate Real Time Clock (RTC)
UEGO - handling Oxygen Sensors
xMisc - left over stuff
yDallas.h - declarations for the Dallas DS18B20 temperature sensors
zz.h - Prototype functions
#include zz.h is in the main tab, but for some reason I can't put all the prototypes in zz.h else every so often, after new code changes, I get random compile errors are often misleading and so very difficult to locate. After much hair-pulling my workaround is to copy certain prototypes to the main tab, so the prototype is now declared in two places.
For example, the following works (in main tab):
/* -- Prototpes ------------------------------------------------------------------ */
// prototype functions required for IDE 1.6.6 (may not be requited in later IDE)
#include "zz.h" // prototype functions (required since IDE 1.6.6 if using multiple tabs)
void reportThermoCode(DeviceAddress & ident);
void displayTime(time_t t, int row, boolean show_date);
time_t computeCorrectedTime(time_t t);
time_t getUTCtime(boolean add_age);
time_t getGPStime(boolean add_age);
time_t correctRTCtimeForDrift(time_t t);
void ReportTime(time_t t, boolean textreport, boolean reportCorrected);
void ReportDuration(time_t duration);
void printDirectory(File dir, int numTabs);
but if I comment a prototype out in the main tab (but not in zz.h), for example:
//void reportThermoCode(DeviceAddress & ident);
I get compile this error, even though same prototype is in zz.h
Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"
Build options changed, rebuilding all
Celsius:52: error: variable or field 'reportThermoCode' declared void
void reportThermoCode(DeviceAddress & ident){
^
Celsius:52: error: 'DeviceAddress' was not declared in this scope
Celsius:52: error: 'ident' was not declared in this scope
void reportThermoCode(DeviceAddress & ident){
^
exit status 1
variable or field 'reportThermoCode' declared void
When this prototype placement rears it's ugly head some of the worst errors to resolve point to a line in a section of code that has been completely commented out ?!? Even moving the order of the prototype statements in the main tab will change the error reported, or may even result in a clean compile.
Not a good situation so I would really like to know why this happens, and how to (reliably) avoid it in future ... TIA
here are the contents of zz.h
// -- Prototype functions ---
void reportThermoCode(DeviceAddress & ident);
void displayTime(time_t t, int row, boolean show_date);
time_t computeCorrectedTime(time_t t);
time_t getUTCtime(boolean add_age);
time_t getGPStime(boolean add_age);
time_t correctRTCtimeForDrift(time_t t);
void printDirectory(File dir, int numTabs);
void ReportTime(time_t t, boolean textreport, boolean reportCorrected);
void ReportDuration(time_t duration);
//
void toggleLogging();
void beep();
void beep2();
void beep3();
void beep4();
void prepareForInterrupts();
void setCelsiusResolutions();
void mapDeviceIds(int b);
void primeCELSIUS();
void gatherCELSIUS();
void blankLCD(unsigned int row);
void reportCELSIUS();
void displayCELSIUS(int row);
bool processGPSbuffer();
void getGPScoordinates();
void getGPScourse();
void getRPM();
int processLCDbuttons();
void printMenu(int first, int last);
void processSomeSerialCommands();
void addLogEntry();
void calculateAFR(float VF, float VR);
void logHeader();
void displayRPM(int row);
void displayGPScoordinates(int row);
void displayAFRs(int row);
void displayCourse(int row);
void hashLCD(unsigned int row);
void displayMode6();
void dotLCD(unsigned int row);
void reportGPScoordinates();
void reportGPScourse();
void printFloat(double number, int digits, int decimals);
void reportRPM();
void Timed0250();
void Timed0500();
void Timed2000();
void Timed5000();
void listCodesActiveThermometers();