 #include <Wire.h>
 #include <LSM303.h>
 
-/* This example uses ZumoMotors, Wire, and LSM303 (compass) library to 
- * drive the Zumo in squares. To do this, the Zumo first calibrates 
- * the compass to account for offsets in its output. Calibration is
- * accomplished in setup().
- *
- * In loop(), The driving angle then changes its offset by 90 degrees 
+/* This example uses the magnetometer in the Zumo Shield's onboard
+ * LSM303DLHC to help the Zumo make precise 90-degree turns and drive
+ * in squares. It uses the ZumoMotors, Pushbutton, and LSM303
+ * (compass) libraries. The LSM303 library is not included in the Zumo
+ * Shield libraries; it can be downloaded from GitHub at:
+ *
+ *   https://github.com/pololu/LSM303
+ *
+ * This program first first calibrates the compass to account for
+ * offsets in its output. Calibration is accomplished in setup().
+ *
+ * In loop(), The driving angle then changes its offset by 90 degrees
  * from the heading every second. Essentially, this navigates the
  * Zumo to drive in square patterns.
  *

  {
    compass.read();
    avg.x += compass.m.x;
    avg.y += compass.m.y;       
  }
  avg.x /= 10.0;
  avg.y /= 10.0;

  // avg is the average measure of the north vector.
  return heading(avg);    
}
  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))
  {
