Hi,
I have a project with a lot of large constant strings, so thought I'd offload them to EEPROM and only address the ones I need in limited scopes as I need them.
To do this I thought I'd have a "#define SETUPMODE" which could be commented out after the sketch had been run once and all those strings would be gone, replaced by addresses in EEPROM to save space. Problem is when I comment out that line the compiler gives an error in the first line of setup(), 'Serial' was not defined in this scope. I simplified the sketch to illustrate the point, and the below simplified version does the same.
With the SETUPMODE definition it runs, without, it doesn't compile.
Any ideas why this might be?
// comment this line to put in RUN mode
#define SETUPMODE
// comment this line to remove USB debug printlns
#define DEBUG
// debugging functions controlled by the above definition
#ifdef DEBUG
#define DEBUG_PRINT(x) Serial.print (x) // print text to USB
#define DEBUG_PRINTDEC(x) Serial.print (x, DEC) // print value to USB
#define DEBUG_PRINTLN(x) Serial.println (x) // print text with newline to USB
#else
#define DEBUG_PRINT(x)
#define DEBUG_PRINTDEC(x)
#define DEBUG_PRINTLN(x)
#endif
/* this block only present if in Setup mode - once Setup has been run once,
all these values are safely stored in the Arduino's onboard EEPROM. */
#ifdef SETUPMODE
// declare things that only get used for setupmode
int testvar = 5;
#endif
// global scop declarations common to RUN and SETUPMODE go here
int testval = 5;
void setup() {
Serial.begin(9600); // for talking with Arduino IDE over USB
#ifdef SETUPMODE
Serial.println("Setup mode enabled.");
#else
Serial.println("Standard mode enabled.");
#endif
}
void loop() {
#ifdef SETUPMODE
Serial.println("Setup complete, comment out #define SETUPMODE in sketch and re-upload to Arduino.");
#endif
for(;;); // do nothing, forever
}
I have a sneaking suspicion I've been staring at the reason all night so hoping fresh eyes will see!