Serialprint String and uint8_t


Im using my own debugger print with some color and the name of the class where it is implemented as a .h file

#define LOG(x, ...)  { Serial.println("\x1b[34m"DEBUG": \x1b[39m"x"\x1b[39;49m");}

Which Im using like this

#define DEBUG "DRV8825 Motordriver"
#include "h_logger.h"

If im using it like this

LOG("Setting Motor Power to ");

there is no problem but these two give me an error. With state as uint8_t

 LOG("Setting Motor Power to " + state);

or even

   String debugString = "test123";

The error is the following

In file included from drv8825.cpp:4:0:
drv8825.cpp: In member function 'void drv8825::powerOn(bool)':
drv8825.cpp:68: error: expected ')' before 'debugString'
h_logger.h:7:66: note: in definition of macro 'LOG'
 #define LOG(x, ...)  { Serial.println("\x1b[34m"DEBUG": \x1b[39m"x"\x1b[39;49m");}
expected ')' before 'debugString'
#define LOG(x, ...)  { Serial.println("\x1b[34m"DEBUG": \x1b[39m"x"\x1b[39;49m");}

The double quotes in that println() call don't appear to match. Why not make it very clear what the macro does by using multiple lines, and multiple calls to Serial.print() and/or Serial.println()? I think that if you do, it will become quite clear what the problem is.

Well, it looks okay to me and it also works with a simple LOG(“test123”)

Here it is with colors in the IDE, this looks a little clearer than in the forum code format

To make it clear, the code in front and back is the ANSI Code for debug messages

EDIT: Got it working, just needed some more minutes for fiddling around :smiley:

I have to cast the x to String first.

This works for me:

#define LOG(x, ...)  { Serial.println("x1b![34m"DEBUG": x1b[39m" + String(x) + "x1b[39;49m");}

Bildschirmfoto 2015-05-27 um 13.41.00.png

 LOG("Setting Motor Power to " + state);

This isn't java. You don't get to use the + operator to join strings like that. What you essentially have here is trying to add together a pointer to the static string on the left with the integer value on the right.