 
 void loop() {
   // Get distance from sensor
-  iter ++;
+  iter++;
   if (iter == 1) {
+    //print out values from sensors and motors to the console
     distance = sensor.getDist();
     distance2 = sensor2.getDist();
     Serial.print(past);

  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  past = 'f';
  count = 0;
  iter = 0;
  threshold = analogRead(backleft) - 200;

  } else if (iter == 5) {
    iter = 0;
  }
  if (analogRead(backleft) < threshold) { //first read from line sensors before doing anything else
    //if line detected by back-left line sensor, turn left a bit
    move(1, 40, 1); //motor 1, full speed, left
    move(2, 120, 0); //motor 2, full speed, left
    past = 'f'; //set default move to forward
    delay(50); //wait 50ms for the IR sensors to take new reading
  } else if (analogRead(backright) < threshold) {
    //if line detected by back-right line sensor, turn right a bit
    move(1, 120, 1); //motor 1, full speed, left
    move(2, 40, 0); //motor 2, full speed, left
    past = 'f';
    delay(50);
  } else if (analogRead(frontleft) < threshold) {
    //if line dectected by front-left sensor, go back and to the left a bit
    move(1, 40, 0); //motor 1, full speed, left
    move(2, 120, 1); //motor 2, full speed, left
    past = 'f';
    delay(50);
  } else if (analogRead(frontright) < threshold) {
    //if line detected by front-right sensor, go back and to the right a bit
    move(1, 120, 0); //motor 1, full speed, left
    move(2, 40, 1); //motor 2, full speed, left
    past = 'f';
    delay(50);
  } else if (iter == 1){
    if (((past == 'f' || count >= 100) && (distance > 600 && distance2 > 600)) || (distance <= 300 && distance2 <= 300) || (abs(distance - distance2) <= 150)) {
      //if (robot moved forward in the past OR it's been searching for 100 iterations) AND (there isn't an object within 600mm of either IR sensor))
      //OR there is an object within 300mm of both sensors 
      //OR the difference between the two distances measured by the IR sensors is within 150mm of each other
      //move forward
      move(1, 128, 1); //motor 1, full speed, left
      move(2, 128, 0); //motor 2, full speed, left
      past = 'f'; //set past movement to forward
      count = 0; //reset abandon search count
    } else if (past == 'l') {
      //if robot has been moving left in the past, move left more
      move(1, 20, 1); //motor 1, full speed, left
      move(2, 128, 0); //motor 2, full speed, left
      past = 'l'; //set past movement to left
      count++; //increment abandon search count
    } else if (past == 'r') {
      //if robot has been moving right in the past, move right
      move(1, 128, 1); //motor 1, full speed, left
      move(2, 20, 0); //motor 2, full speed, left
      past = 'r'; //set past movement to right
      count++; //increment abandon search count
    } else if (distance > 600) {
      //if there is an object beyond 600mm of the right sensor (i.e. there is something closer in the left sensor), move left
      move(1, 20, 1); //motor 1, full speed, left
      move(2, 128, 0); //motor 2, full speed, left
      past = 'l'; //set past movement to left
      count = 0; //reset abandon search count because the robot has found an object
    } else {
      //else (i.e. there is an object closer in the right sensor), move right
      move(1, 128, 1); //motor 1, full speed, left
      move(2, 20, 0); //motor 2, full speed, left
      past = 'r'; //set past movement to right
      count = 0; //reset abandon search count
    }
  }
  
  // Print distance to Serial
  // Wait some time
