 
 const int buttonPin = 10;
 
-const int minServoAngle = 700;
-const int maxServoAngle = 2300;
-const int numberOfUsableDegrees = maxServoAngle - minServoAngle;
-const int centerServoAngle = minServoAngle + numberOfUsableDegrees / 2;
+const int MIN_SERVO_DEGREES = 0;
+const int MAX_SERVO_DEGREES = 180;
+const int MIN_NORM_DEGREES = -90;
+const int MAX_NORM_DEGREES = 90;
+const int USABLE_DEGREES = MAX_SERVO_DEGREES - MIN_SERVO_DEGREES;
+
+const int SERVO_DELAY = 15; // millis
 
 Servo panServo;
 Servo tiltServo;

}

int convertNormalizedAngleToServoAngle(int normalizedAngle) {
  return normalizedAngle + minServoAngle;
}

void drawCircle(int centerX, int centerY, int radius, int xDegreesPerCycle) {

}

void drawEllipse(int centerX, int centerY, int radiusX, int radiusY, int xDegreesPerCycle) {
  const int maxDisplacementFromCenter = USABLE_DEGREES / 2;

  const int startX = centerX - radiusX;
  const int endX = centerX + radiusX;

  for (int targetDegrees = startX; targetDegrees <= endX; targetDegrees += xDegreesPerCycle) {
    const int targetPanServoDegrees = convertNormalizedAngleToServoAngle(targetDegrees);
    
    panServo.write(targetPanServoDegrees);

    const int targetTiltDegrees = centerY - sqrt(pow(radiusY, 2) * (1.0 - pow(targetDegrees - centerX, 2) / pow(radiusX, 2)));
    const int targetTiltServoDegrees = convertNormalizedAngleToServoAngle(targetTiltDegrees);
    tiltServo.write(targetTiltServoDegrees);

    delay(SERVO_DELAY);
  }

  for (int targetDegrees = endX; targetDegrees > startX; targetDegrees -= xDegreesPerCycle) {
    const int targetPanServoDegrees = convertNormalizedAngleToServoAngle(targetDegrees);
    
    panServo.write(targetPanServoDegrees);

    const int targetTiltDegrees = centerY + sqrt(pow(radiusY, 2) * (1.0 - pow(targetDegrees - centerX, 2) / pow(radiusX, 2)));
    const int targetTiltServoDegrees = convertNormalizedAngleToServoAngle(targetTiltDegrees);
    tiltServo.write(targetTiltServoDegrees);

    delay(SERVO_DELAY);
  }
}

void performRangeTest() {
  moveToPoint(0, 0, 50);
  moveToPoint(-90, 90, 50);
  moveToPoint(-90, -90, 50);
  moveToPoint(90, -90, 50);
  moveToPoint(90, 90, 50);
  moveToPoint(-90, 90, 50);
  moveToPoint(0, 0, 50);
}
}

void loop() {
  const int buttonState = digitalRead(buttonPin);

  if (buttonState == LOW) {
//    performRangeTest();

//    drawCircle(0, 0, numberOfUsableDegrees / 2, 15);

    drawEllipse(0, 0, USABLE_DEGREES / 4, USABLE_DEGREES / 4, 3);
  }
}
