    * multiply that by 0.1875, and divide that by 1000 to get voltage
    * in volts.
    */
-  resultmV = cVoltage;
-  resultV = cVoltage/1000;
+   resultSd = (cVoltage-intercept)*slope;
+   resultS = resultSd;
+   resultmV = cVoltage;
 }
 
 void SDwrite() {
-  resultFile = SD.open(fileName, FILE_WRITE);
-  if(!resultFile){
-    LCDwrite("Cannot open", fileName);
-    delay(1000);
-    }
-  lcd.clear();
-  resultFile.println(resultmV + ","); //writes to SD card
+  File file = SD.open(fileName, FILE_WRITE);
+  if (!file){
+    LCDwrite("Error writing to", fileName);
+    while(1);
+    }
+    else {
+      if (resultSd > 0) {
+    file.println(resultS + "," + resultmV + "," + millis()); //writes to SD card
+    file.close();
+  } else {
+    delay(0);
+    }
+    }
 }
 
 void writeResult(){ //Writes result to SD card and LCD Screen
   readADS(); //Reads data from ADC
   SDwrite(); //Write data to SD card
-  LCDwrite((resultV + " V"), (resultmV + " mV ")); //Space keeps unnecessary "V" from appearing
+  LCDwrite((resultS + " uS    "), (resultmV + " mV    ")); //Space keeps unnecessary "V" from appearing
 }
 
 void titleAndInitialize(){

    delay(3000);
    lcd.clear();
  }
  }





const int clk = 13; //Clock pin
const int PP = 3; //Peristaltic pump pin

//Time-keeping variable
//unsigned long time;

//Set values for time it takes to circulate the 100mL 
//bulk solution 5x through apparatus at pump speeds
const int mlSpeed40 = 150000;
const int mlSpeed20 = 300000;
const int mlSpeed10 = 600000;

//Record how many times water has been circulated through apparatus
int cycle = 0;

void setup() {
  //Set pin modes
  pinMode(MOSIpin, OUTPUT);
