I've run into a weird problem with (I presume) the compiler and managed to reduce it to a few small test cases. I have tested them on V.0023 and V1.0 and they all work/fail the same way - I have a Duemilanove 328.
I'll start with the code from the description of setup() at setup() - Arduino Reference
This compiles (as it should):
int buttonPin = 3;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
}
void loop()
{
// ...
}
Now let's suppose that the use of the buttonPin is optional and modify it so that it can be removed with ifdef - this also compiles:
#define NO_BUTTON
#ifdef NO_BUTTON
int buttonPin = 3;
#endif
void setup()
{
Serial.begin(9600);
#ifdef NO_BUTTON
pinMode(buttonPin, INPUT);
#endif
}
void loop()
{
// ...
}
BUT if I decide I don't want the button, commenting the define out like this:
//#define NO_BUTTON
#ifdef NO_BUTTON
int buttonPin = 3;
#endif
void setup()
{
Serial.begin(9600);
#ifdef NO_BUTTON
pinMode(buttonPin, INPUT);
#endif
}
void loop()
{
// ...
}
gives the compiler error message:
test23.cpp: In function 'void setup()':
test23:6: error: 'Serial' was not declared in this scope
Why?
Pete
P.S. I searched for this message and couldn't find any solution.