Skip to main content
Extended answer
Source Link
Tim MB
  • 111
  • 3

For debug printing, you can define a macro to print both the name and value of a variable like this:

#define PRINTLN(var) Serial.print(#var ": "); Serial.println(var)

which you then use like this:

int x = 5;
PRINTLN(x); 

// Prints 'x: 5'

Also this is nice:

#define PRINT(var) Serial.print(#var ":\t"); Serial.print(var); Serial.print('\t')
#define PRINTLN(var) Serial.print(#var ":\t"); Serial.println(var)

when used in a loop like so

PRINT(x);
PRINT(y);
PRINTLN(z);

prints an output like this:

x:  3   y:  0.77    z:  2
x:  3   y:  0.80    z:  2
x:  3   y:  0.83    z:  2

For debug printing, you can define a macro to print both the name and value of a variable like this:

#define PRINTLN(var) Serial.print(#var ": "); Serial.println(var)

which you then use like this:

int x = 5;
PRINTLN(x);
// Prints 'x: 5'

For debug printing, you can define a macro to print both the name and value of a variable like this:

#define PRINTLN(var) Serial.print(#var ": "); Serial.println(var)

which you then use like this:

int x = 5;
PRINTLN(x); 

// Prints 'x: 5'

Also this is nice:

#define PRINT(var) Serial.print(#var ":\t"); Serial.print(var); Serial.print('\t')
#define PRINTLN(var) Serial.print(#var ":\t"); Serial.println(var)

when used in a loop like so

PRINT(x);
PRINT(y);
PRINTLN(z);

prints an output like this:

x:  3   y:  0.77    z:  2
x:  3   y:  0.80    z:  2
x:  3   y:  0.83    z:  2
Source Link
Tim MB
  • 111
  • 3

For debug printing, you can define a macro to print both the name and value of a variable like this:

#define PRINTLN(var) Serial.print(#var ": "); Serial.println(var)

which you then use like this:

int x = 5;
PRINTLN(x);
// Prints 'x: 5'