     Serial.print("   Straight");
 
     delay(1000);
-    
+
     // turn off motors and wait a short time to reduce interference from motors
     motors.setSpeeds(0, 0);
     delay(100);
-    
+
     // We now want to turn 90 degrees relative to the direction we are pointing at.
     // This will help account for variable magnetic field.
     targetHeading = (averageHeading() + 90) % 360;
-  } 
-  else 
+  }
+  else
   {
     if((relHeading - DEVIATE_RIGHT_THRESHOLD) < (DEVIATE_LEFT_THRESHOLD - relHeading))
     {

  Serial.print("min.y   ");
  Serial.print(running_min.y);
  Serial.println();
  
  // Set calibrated values to compass.m_max and compass.m_min
  compass.m_max.x = running_max.x;
  compass.m_max.y = running_max.y; 
  compass.m_min.x = running_min.x;
  compass.m_min.y = running_min.y;
  
  button.waitForButton();
}

void loop() 
{  
  int heading, relHeading;
  static int targetHeading = averageHeading();
  
  // LSM303::vector{1,0,0} starts our heading to point North
  // Heading is given in degrees away from North, increasing clockwise
  heading = averageHeading();
  
  // This gives us our relative heading in respect to the angle we want to drive in
  relHeading = relativeHeading(targetHeading, heading);
  
  Serial.print("Target heading: ");
  Serial.print(targetHeading);
  Serial.print("    Actual heading: ");
  Serial.print(heading);
  Serial.print("    Difference: ");
  Serial.print(relHeading);
  
  // If we have turned to the direction we want to be pointing, go straight and then do another turn
  if((relHeading < DEVIATE_RIGHT_THRESHOLD) || (relHeading > DEVIATE_LEFT_THRESHOLD))
  {

  {
    // Read in magnetic vector m
    compass.read();

    running_min.x = min(running_min.x, compass.m.x);
    running_min.y = min(running_min.y, compass.m.y);

    running_max.x = max(running_max.x, compass.m.x);
    running_max.y = max(running_max.y, compass.m.y);

    Serial.println(index);

    delay(50);
  }

  motors.setLeftSpeed(0);
  motors.setRightSpeed(0);

  Serial.print("max.x   ");
  Serial.print(running_max.x);
  Serial.println();
