Strung along on Strings.....

How does one insert variables into a string being passed to another proceedure?
for example:

Debug("X Max=" + X_Max + "; X Min=" + X_Min + "; X Center=" + (X_Max-X_Min)/2);

complains of use of binary operator '+' with const char[9] and char*. I would almost kill for a built in debug object.

You could use the Streaming library, and the C++ style output.

Without that, though, you are stuck with the C printf style of output. You really need to use several statements to get the output that you want.

I was afraid of that, not really just entrenched in my win32 ways.. I'll make each section a .print() with the last section being a .println().

C++ sucks for formatting output especially when it contains a variable number of arguments.

It looks like standard C xxprintf() formatting type functionality is what you are looking for.

If all you need to do is create a string for debugging output, then use sprintf().

char buf[64]; // don't create strings larger than this (declare this up top out side setup()/loop() )

sprintf(buf, "X Max=%d X Min=%d X Center=%d", X_Max, X_Min, (X_Max-X_Min)/2);
Serial.println(buf);

And if you want to get a bit fancy you can use some macros and tie into
the AVR libc vfprintf() stuff to give you a Debug() call to output your strings.

I attached an example sketch that does this.
It has the advantage of automagically moving the formatting strings into progmem
so you don't chew up ram and also does not have to use a static fixed size buffer.
Have a look.

Using the code in that example sketch, you could output your debugging information like this:

Debug("X Max=%d X Min=%d X Center=%d\n", X_Max, X_Min, (X_Max-X_Min)/2);

--- bill

Note: corrected Debug() example above....

serialprintf.zip (755 Bytes)

Thanks Bill, I am looking at your code now. I am still alot vague on how to use pointers and references as args in C, I am so used to explicit keywords such as Set and Let and getRef(). I may pull all my many folicles out before I get a grip, but I will succeed as failure is not an option.

This is what I do for debugging quickly

#ifdef DEBUG

#define DEBUG_VAR(variable) do {Serial.print(#variable " = "); Serial.print(variable); Serial.print("\t");} while (0)
#define DEBUG_LAST() do { Serial.println(); } while (0)

#else // DEBUG
#define DEBUG_VAR(x) (void) 0
#define DEBUG_LAST() (void) 0
#endif //DEBUG

Then when you want to print a variable you just do:

int x = 27;
int y = 29;
int z = x + y;
DEBUG_VAR(x);
DEBUG_VAR(y);
DEBUG_VAR(z);
DEBUG_LAST();

and it will print

x = 27     y = 29     z = 56