Trying to reduce serial.print code

Hey guys, I am just wondering if there is any way to reduce this code and make it two or three lines. The vars without quotations have values assigned to them. I need to print a space or a semi colon between the values for ease of exporting into excell. I have tried Serial.print((tTest)";"(Vin0)";"(Vin1)";"(Vin2)";"(Vin3)";"(Vin4)";"); but it says expected ')' before string constant.

Serial.print("#S|THRMLOG|[");
    tTest = millis() - tStart;
    Serial.print(tTest);
    Serial.print(";");
    Serial.print(Vin0);
    Serial.print(";");
    Serial.print(Vin1);
    Serial.print(";");
    Serial.print(Vin2);
    Serial.print(";");
    Serial.print(Vin3);
    Serial.print(";");
    Serial.print(Vin4);
    Serial.print(";");
    Serial.print(Vin5);
    Serial.print(";");
    Serial.print(Vin6));
    Serial.print(";");
    Serial.print(Vin7);
    Serial.print(";");
    Serial.print(Vin8);
    Serial.print(";");
    Serial.println("]#");

**SOLVED:**Thank you again for all of the input.

my new code works great:

#include <math.h>
int TTLPin = 51; 
long tTest = 0;
long tStart;
int myPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8};
int myVin[9]; 

void setup()
{
  Serial.begin(9600);
  pinMode(TTLPin, INPUT);
  
} 
void loop(){ 
  
  Serial.println("#S|CPBLTST|[]#");
  Serial.println("#S|THRMLOG|[Time(ms);Vin0;Vin1;Vin2;Vin3;Vin4;Vin5;Vin6;Vin7;Vin8]#");
  //while(digitalRead(TTLPin) == LOW){}
  tStart = millis();
  while(true){
          
    int i;
    for (i=0; i<9; i++){    
         myVin[i] = analogRead(myPins[i]); 
    }
    
    Serial.print("#S|THRMLOG|[");
    tTest = millis() - tStart; 
    Serial.print(tTest);
    Serial.print(";");
    
    int j;
    for(j=0; j<9; j++){
       Serial.print(myVin[j]);
       Serial.print(";");
    }
    Serial.println("]#");  
    
    delay(1000);
  }
    
}

It's quite likely that using an array for those vin numbers would not only help here, but elsewhere in your sketch too.

char tempStr[80];

sprintf(tempStr,"#S|THRMLOG|[%lu;%d;%d;%d;%d;%d;%d;%d;%d;%d;]#",
  tTest,Vin0,Vin1,Vin2,Vin3,Vin4,Vin5,Vin6,Vin7,Vin8);
Serial.println(tempStr);

That is assuming VinX are ints. For float values it gets somewhat more complex as the sprintf code doesn't handle floats. For that you will have to do some majoc using dtostrf() and more strings.

Why aren't the "Vin"s array elements?

majenko:

char tempStr[80];

sprintf(tempStr,"#S|THRMLOG|[%lu;%d;%d;%d;%d;%d;%d;%d;%d;%d;]#",
  tTest,Vin0,Vin1,Vin2,Vin3,Vin4,Vin5,Vin6,Vin7,Vin8);
Serial.println(tempStr);




That is assuming VinX are ints. For float values it gets somewhat more complex as the sprintf code doesn't handle floats. For that you will have to do some majoc using dtostrf() and more strings.

Okay thats great that helps me understand sprintf better.

Also its pretty clear that I need to start getting used to using arrays rather than declaring each variable separately.

I just skimmed through. In addition to sprintf() maybe you can try Streaming | Arduiniana. Note that sprintf() in Arduino does not work with floats.