Multiple Variables in a Single Serial.write command

Dear All,

I basically want to communicate data using Bluetooth. Right now, my code looks like this:

  sensorValue1= analogRead(1);
  sensorValue2= analogRead(2);
  sensorValue3= analogRead(3); 
  
  bluetooth.write(sensorValue1);
  bluetooth.write(sensorValue2);
  bluetooth.write(sensorValue3);
  bluetooth.write(44);

I was just wondering if there was a way to send the packet using 1 line. I know that some parts of my code are wrong (A/D conversion is 10-bits and I'm only sending 8-bit at a time), but the general inquiry is the same.

Thanks

You can use sprintf() to merge them into a char string and then send that. But to be honest that just wastes memory. There is no real difference between sending it in several commands and sending it in one go. You can't guarantee that the device on the other end or the Bluetooth module is processing the data as fast - e.g. you might send 10 characters, but on the other end whatever reads it might make one read and get 6, and then a second read to get the remaining 4.

Ok. If there's not too much of a change, then it doesn't matter if I print them separately as long as I use a comma to delimit each dataset.

Thanks for the help!

Ok. If there's not too much of a change, then it doesn't matter if I print them separately as long as I use a comma to delimit each dataset.

Except that you are not print()ing the values. You are write()ing them. The two methods do quite different things.

Putting a comma between print()ed values is a necessary thing. Putting commas between binary values is uesless.