My current wall-following robot uses two different serial ports for telemetry reporting - Serial (the normal USB port), and Serial1 (a HC-05 BT module). I have to send the same telemetry to both ports, because either or both can be active.
In my code are lines like this:
Serial.printf("\nChecking for MPU6050 IMU at I2C Addr 0x%x\n", MPU6050_I2C_ADDR);
Serial1.printf("\nChecking for MPU6050 IMU at I2C Addr 0x%x\n", MPU6050_I2C_ADDR);
I would like to create a function like 'SendToBothPorts(??)' so that I don't have to keep writing (or copy/pasting) the same stuff twice every time I want to send to both ports.
I have tried playing around with strcpy and strcat, like so:
but the '\n' construct gets interpreted even though it is within double-quotes, so the output looks like:
I'm thinking there must be a better way to do this, but I can't figure it out - any ideas would be appreciated
TIA,
Frank
In my code are lines like this:
Serial.printf("\nChecking for MPU6050 IMU at I2C Addr 0x%x\n", MPU6050_I2C_ADDR);
Serial1.printf("\nChecking for MPU6050 IMU at I2C Addr 0x%x\n", MPU6050_I2C_ADDR);
I would like to create a function like 'SendToBothPorts(??)' so that I don't have to keep writing (or copy/pasting) the same stuff twice every time I want to send to both ports.
I have tried playing around with strcpy and strcat, like so:
Code:
char quotestr[] = "\"";
char hellostr[] = "hello";
char instr[] = "%s\n, hellostr";
char deststr[40];
memset(deststr, 0, sizeof(deststr));
strcat(deststr, quotestr);
strcat(deststr, instr);
strcat(deststr, quotestr);
Serial.printf("quotestr = %s\n", quotestr);
Serial.printf("instr = %s\n", instr);
Serial.printf("deststr = %s\n", deststr);
Serial.printf(deststr);
but the '\n' construct gets interpreted even though it is within double-quotes, so the output looks like:
Code:
quotestr = "
instr = %s
, hellostr
deststr = "%s
, hellostr"
"
, hellostr"
I'm thinking there must be a better way to do this, but I can't figure it out - any ideas would be appreciated
TIA,
Frank