   // starting a trial
   trialtime = millis();
 
-  if (cs <= ISI) {
+  if (csdur <= ISI) {
     doTrace();
   }
   else { doDelay(); }

// Task variables (time in ms, freq in hz)
int campretime = 200;
int camposttime = 800;
int cs = 500;
int csch = 1;   // default to LED
int usch = 3;   // default to ipsi corneal puff
int ISI = 200;
int us = 20;
int residual;
int tonefreq5 = 10000;

unsigned long trialtime = 0; // For keeping track of elapsed time during trial



  usON();
  
  if (csdur < (ISI+usdur)) {
   delay(csdur-ISI);
   csOFF();
   residual = usdur - (csdur-ISI);
  }
  else {
    residual = usdur;
  }   
  
  delay(residual);                  // wait for remainder of us (or all if cs is longer)
  
  usOFF();

  residual = csdur - ISI - usdur;
  if (residual > 0) {
    delay(residual);          // wait for whatever additional time cs is on
  }
