 void loop() {
   // establish variables for duration of the ping,
   // and the distance result in inches and centimeters:
-  long duration, inches, cm;
+  
 
+  rotateStep(false);
+  pingDist = measurePingDist();
+  measurements[nRotations] = pingDist;
+  Serial.println(String(measurements[nRotations]));
+  ++nRotations %= nMeasurements;
+
+  delay(100);
+}
+long measurePingDist(){
+  long duration, cm;
   // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
   // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
   pinMode(pingPin, OUTPUT);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);

  Serial.println(String(cm)+" cm");

  rotateStep(false);

  delay(100);
}

void rotateStep(bool clockwise) {

    servoLeft.writeMicroseconds(1300);
    servoRight.writeMicroseconds(1300);
  }
  delay(100);
  servoLeft.writeMicroseconds(1500);
  servoRight.writeMicroseconds(1500);
}
