Servo pulse to degrees

Hi,

I am trying to understand the way in which a servo is set to a specific degree depending on the pulseMin pulseMax and time.

I found this on the adafruit site that the following function converts degrees to pulse values.

pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX);

So can i do this to calculate the reverse.

degrees = map(pulselength, SERVOMIN, SERVOMAX, 0, 180);

I don't know if I am over simplifying this as it feels like i need to take into account the update time.
I did try to find a already existing topic on this as i thought there must be a few but i couldn't so sorry if i have duplicated this.

Thank you

as far as i could say yes.
but why dont you try it yourself....

It's not clear where you are getting the data you want to map. Are you reading pulse length from somewhere? If so, mapping that to degrees makes sense.

If you are reading degrees from somewhere, mapping that to pulse time is a matter for the Servo library to deal with.

I am trying to understand the way in which a servo is set to a specific degree depending on the pulseMin pulseMax and time.

The actual amount of rotation available from a servo can vary from servo to servo (I’ve had some servos that could rotate ~190 deg). With the servo library, the degrees entered is internally mapped to a us value. Below is some servo test code that can be used to check the rotation range of your servos. Note that you may need to use the servo.attach(pin, 500, 2500) to ensure full us range for testing.

http://arduino.cc/en/Reference/ServoAttach

// zoomkat 10-22-11 serial servo test
// type servo position 0 to 180 in serial monitor
// or for writeMicroseconds, use a value like 1500
// for IDE 0022 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.writeMicroseconds(1500); //set initial servo position if desired
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-22-dual-input"); // so I can keep track of what is loaded
}

void loop() {
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n = readString.toInt();  //convert readString into a number

    // auto select appropriate value, copied from someone elses code.
    if(n >= 500)
    {
      Serial.print("writing Microseconds: ");
      Serial.println(n);
      myservo.writeMicroseconds(n);
    }
    else
    {   
      Serial.print("writing Angle: ");
      Serial.println(n);
      myservo.write(n);
    }

    readString=""; //empty for next input
  } 
}