Separate measurement

Hello,

I am on project, and i have to do a program on consisting in receiving analog measurement and write it down on a SD card, it start when i have my A1 input is above 20.
The file on SD card looks like this :

A2 : 160
A2 : 160
A2 : 160

What i want to do is separate those measurements in groups to looks like this :

Measure 1 : //A1 is above 20
A2 : 160
A2 : xxx
A2 : xxx //A1 is under 20 the measurement is stopped
Measure 2 : //A1 returns above 20
A2 : 158
A2 : xxx
A2 : xxx

But i don’t know how to do it, so if anyone can help me it would be great :slight_smile:
PS: I’m on Yùn card
Thanking you in advance

#include <FileIO.h>

void setup() {
  // Initialize the Bridge and the Serial
  Bridge.begin();
  Serial.begin(57600);
  FileSystem.begin();

  while(!Serial);  // wait for Serial port to connect.
  Serial.println("Filesystem datalogger\n");
}

void loop () {
  int Start = analogRead(A1);
  
  if (Start > 20) {
   
   String dataString;
     dataString += "A2 : ";
     int sensor = analogRead(A2);
     dataString += String(sensor);
     
   File dataFile = FileSystem.open("/mnt/sd/arduino/www/datalog.txt", FILE_APPEND);

   if (dataFile) {
     dataFile.println(dataString);
     dataFile.close();
     Serial.println(dataString);
   }  
   // if the file isn't open, pop up an error:
   else {
     Serial.println("error opening datalog.txt");
   } 
}
  delay(1000);
}

How about using an else to change the data string to something like this.

 if (Start > 20) {
     String dataString;
     dataString += "A2 : ";
     int sensor = analogRead(A2);
     dataString += String(sensor);
 }
 else
     dataString += "A2 : Less than 20";