 }
 
 void calcDistance() {
-  if (iterator == 20) {
-    iterator = 0;
-  }
-  prevLeft = leftDistance;
-  prevRight = rightDistance;
-/* The following trigPin/echoPin cycle is used to determine the
- distance of the nearest object by bouncing soundwaves off of it. */ 
-// digitalWrite(leftTrig, LOW); 
-// delayMicroseconds(2); 
-// digitalWrite(leftTrig, HIGH);
-// delayMicroseconds(10); 
-// digitalWrite(leftTrig, LOW);
-// duration = pulseIn(leftEcho, HIGH);
+ prevLeft = leftDistance;
+ prevRight = rightDistance;
+ //The following trigPin/echoPin cycle is used to determine the
+ //distance of the nearest object by bouncing soundwaves off of it.
  //Calculate the distance (in cm) based on the speed of sound.
  delay(10);
-  digitalWrite(leftTrig, LOW);
-  delayMicroseconds(5);
-  digitalWrite(leftTrig, HIGH);
-  delayMicroseconds(10);
-  digitalWrite(leftTrig, LOW);
-  pinMode(leftEcho, INPUT);
-  durationLeft = pulseIn(leftEcho, HIGH);
+ digitalWrite(leftTrig, LOW);
+ delayMicroseconds(5);
+ digitalWrite(leftTrig, HIGH);
+ delayMicroseconds(10);
+ digitalWrite(leftTrig, LOW);
+ pinMode(leftEcho, INPUT);
+ durationLeft = pulseIn(leftEcho, HIGH);
  leftDistance = durationLeft/58.2;  
 
-  delay(10);
- 
-// digitalWrite(rightTrig, LOW); 
-// delayMicroseconds(2); 
-// digitalWrite(rightTrig, HIGH);
-// delayMicroseconds(10); 
-// digitalWrite(rightTrig, LOW);
-// duration = pulseIn(rightEcho, HIGH);
-  digitalWrite(rightTrig, LOW);
-  delayMicroseconds(5);
-  digitalWrite(rightTrig, HIGH);
-  delayMicroseconds(10);
-  digitalWrite(rightTrig, LOW);
-  pinMode(rightEcho, INPUT);
-  durationRight = pulseIn(rightEcho, HIGH);
- //Calculate the distance (in cm) based on the speed of sound.
- rightDistance = durationRight/58.2;  
-
-// if((leftDistance<minimumRange)||(leftDistance>maximumRange)) {
-//  leftDistance = prevLeft;
-// }
-// if((rightDistance<minimumRange)||(rightDistance>maximumRange)) {
-//  rightDistance = prevRight;
-// }
-
-//button
-//esc code
- 
-// iterator++;
-// leftDistance = 0;
-// rightDistance = 0;
-// for (int j= 0; j < 20; j++) {
-//  leftDistance += lD[j];
-//  rightDistance += rD[j];
-// }
-// leftDistance = leftDistance/20;
-// rightDistance = rightDistance/20;
+ delay(10);
+
+ digitalWrite(rightTrig, LOW);
+ delayMicroseconds(5);
+ digitalWrite(rightTrig, HIGH);
+ delayMicroseconds(10);
+ digitalWrite(rightTrig, LOW);
+ pinMode(rightEcho, INPUT);
+ durationRight = pulseIn(rightEcho, HIGH);
+ rightDistance = durationRight/58.2; 
+
+ readLine();
 }
 
 /*

  pinMode(rightTrig, OUTPUT);
  pinMode(rightEcho, INPUT);

  //search();
}

void loop(){
  search();
}

void move(int motor, int speed, int direction){

void search() {
  while(!found) {
    // 0 is forward, 1 is backward
    move(1, 200, rightDir); //right motor
    move(2, 200, leftDir); //left motor
    calcDistance();
    //Serial.print("left: ");
    Serial.print(leftDistance);
    Serial.print(",");
    Serial.println(rightDistance);
    //delay(10);
    if(lost) {
      if(diff>0){//turn right
        rightDir = 0;
