cyberjupiter:
Thanks PaulS.One question, is there really a difference between using yours and
#define NAME1 value
#define NAME2 value
Which executes faster?
Neither one "executes" at all! #defines are pre-processor macros. They modify the source code BEFORE it is handed to the compiler, by simply doing a literal cut-and-paste of every instance of the macro name with the macro body. There is a bit more to it than that, but not much. Read up on the c pre-processor for more details.
If you write this in your .ino file:
#define HEEBIE for(int x=1; x<10; x)
#define JEEBIE { Serial.println(x*x); }
void setup()
{
HEEBIE JEEBIE
}
The source file passed to the compiler looks like this:
void setup()
{
for (int x=1; x<10; x++) { Serial.println(x*x); }
}
Every instance of the word "HEEBIE" will be replaced with the for statement. Every instance of the word "JEEBIE" is replaced with the print statement and curly-braces. The pre-processor does not evaluate the expression or check it for correct c/c++ syntax. It only does a fairly dumb string replace, checking only for the presence of OTHER previouslly defined macros within the macro body, and expanding them if found.
Note the blank lines at the top of the file, where the macro definitions have been deleted, as they are no longer needed after they are parsed by the pre-processor.
Regards,
Ray L.