Hello,
I have a project (based on Uno) with a bunch of SoftwareSerial ports defined. I want to send a given piece of output to a given SoftwareSerial port, based on program logic. At the moment I am doing this with a switch case statement, and a case for each port, but this seems clunky and inelegant, and I wonder if there is a better way?
I am wondering whether I can wrap SoftwareSerial in a typedef struct, then create an array of the new data type. Then I could choose a port based on the array index. I'm aiming at something a bit like this (I know this code is wrong!)
typedef struct {
SoftwareSerial mySerial();
} SerialWrapper;
SerialWrapper SerialPorts[4];
int PortNum = 1;
char SomeData = 'X'
SerialPorts[PortNum].write('SomeData');
But then I get lost in how to actually instantiate the ports with Rx/Tx pins, .begin, and how to call the writes (I'm not interested in reading from the ports, BTW).
Any hints would be much appreciated!
Andrew