I'm testing some 3.3v pro-mini/433 mhz Lora boards out in the field.
Its proving jolly useful to be able to get serial feedback over a HC-06 Bluetooth serial. After much hunting around I found out how to do this:
//auto& serial = Serial; // comment to switch output to BT conn to phone
#include <SoftwareSerial.h> // uncomment ditto
SoftwareSerial serial(4, 5); // uncomment ditto
... then later ....
serial.begin(BAUD);
Which allows me to simply set my desired Serial output at the top of the sketch, and then leave my code peppered with statements such as :
serial.println("RSSI :");
That's all fine and dandy (and I hope it helps anyone else browsing around here).
But now I want a THIRD option, to simply ignore the serial output. Yes, I know I could comment it out, or start adding conditional statements :
if(DEBUG)
serial.print("ugly");
But here is the background, I will be moving to using the excellent lowpower lib and from experience I know that by merely invoking the Serial port in a sketch which uses that library will start burning power.
So hence i want to be able to do something similar I used to do in my OOP days, which is to invoke a null object - i.e. something that mimics the Serial API but just sends the output to hell or to the equivalent of whatever dev/null is on a uC.
So to summarise I'd like to do the equivalent of :
/* OPTION 1 - usb serial */
//auto& serial = Serial; // comment to switch output to BT conn to phone
/* OPTION 2 - s/w serial */
#include <SoftwareSerial.h> // uncomment ditto
SoftwareSerial serial(4, 5); // uncomment ditto
/* OPTION 3 - NO ACTUAL serial */
NullSerial = serial;
serial.begin(BAUD);
The point of this being I can leave all my print statements where they are and turn on serial output if I need to debug in the future, AND have lowpower do its stuff without forking code.
I've searched over a few days for an example of this, and of course I guess I could just write my own implementation - but I bet a solution exists somewhere, 'you seen one?