Hello, is it possible to include constants (defined with #define) in the Serial.print or Serial.println function? If so, how would this be done?
I was looking at "stringification" in C++, and it seems to indicate you can include the defined constant name prepended with a # (hash) symbol as in the following example:
(https://gcc.gnu.org/onlinedocs/cpp/Stringification.html)
#define WARN_IF(EXP) \
do { if (EXP) \
fprintf (stderr, "Warning: " #EXP "\n"); } \
while (0)
WARN_IF (x == 0);
==> do { if (x == 0)
fprintf (stderr, "Warning: " "x == 0" "\n"); } while (0);
But when I try to include the constant in this way, the Arduino compiler complains of stray # symbol.
For example:
#define THEVALUE hello123
Serial.println("This is the value: " #THEVALUE);
But the compiler doesn't replace the value within strings, so this doesn't work either:
#define THEVALUE hello123
Serial.println("This is the value: #THEVALUE");
These work except in my use-case where the defined value includes commas (it's an array).
(I'm using this to define the IP address for the ethernet module, and since Ethernet.begin requires a byte array for the IP address, I'm defining the IP as #define IP_ADDRESS 192,168,1,100.
Then I want to display it on the serial console so I don't have to depend on a piece of paper taped to the outside of the unit to keep track of the IP address.