This is a simplified version of the present code:
#include <SoftwareSerial.h>
SoftwareSerial swSer1(12, 13, false, 256);
SoftwareSerial swSer2(14, 15, false, 256);
void processSwSer1() {
// do something with swSer1
}
void processSwSer2() {
// do something with swSer2
}
If I want to process swSer1 and swSer2 in only one function,
I have to pass the software serial to a function.
This is what I have so far:
void processSwSer(int Ser, Stream &swSer) {
static byte ndx = 0;
byte rb;
receivedBytes[numBytes];
while ( swSer.available() > 0 )
{
rb = swSer.read();
receivedBytes[ndx] = rb;
ndx++;
}
if ( Ser == 1 ) {
memcpy(receivedBytes1, receivedBytes, sizeof(receivedBytes));
}
else {
memcpy(receivedBytes2, receivedBytes, sizeof(receivedBytes));
}
}
Would it be more performant to use swSer1 and swSer2 inside the function?