I am using 3 of the Arduino Mega2560's Serial Ports. One for USB to PC, one for Bluetooth and one for GPS.
Serial.print prints to the USB port to the PC. However, in the program I want to redefine Serial to Serial2 so that the statement Serial.print will now print to the Bluetooth port. I understand that I could use Serial2.print but it would save a lot of code if I could just change what port is referenced by Serial.print.
The program monitors whether there are characters from both ports.
if (Serial.available() > 0 || BTSerial.available() > 0)
{ if (Serial.available()==0) {incoming_char = BTSerial.read();}
else {incoming_char = Serial.read(); }
If I send a certain command ('s') from the Bluetooth module (via a smartphone), I want all Serial.print statements to now reference the Bluetooth serial port (BTSerial) instead of the USB port.
I could do it with Software.Serial
#include <SoftwareSerial.h> //for the bluetooth communications
SoftwareSerial BTSerial(8,9);
by tying BT Rx to Tx (which I've done with a Pro-Mini) to get Serial.print to print to both ports.
But since the Mega2560 already has multiple serial ports, why not use them instead.
If no simple solution then I will use the hardware solution (BT Rx to Tx).