I am writing an Arduino program that uses Bluetooth on Serial1 to print text to a Bluetooth terninal on an Android phone and also normal Serial to print text to the serial monitor on a laptop. I would like to wrap the Serial.print() and Serial.println() functions so that they work with either or both Serial and Serial1. For example the code below works fine depending on the values of the global variables. But this only works for single chars, but print() and println() can take a very wide variety of datatypes. If I also define overloading functions for int and String types it works fine, but that is a very verbose and maybe fragile solution, it also ignores the optional inputs to the underlying functions. What is the proper way to do this ?
void print(char x) {
if (g_use_Serial)
Serial.print(x);
if (g_use_Serial1)
Serial1.print(x);
}
void println(char x) {
if (g_use_Serial)
Serial.println(x);
if (g_use_Serial1)
Serial1.println(x);
}