Servo and PWM without library

So I want to control a servo WITHOUT using the servo library for the arduino. I found a site that gave a code to do this, but it only worked for a parallax servo. I have a TowerPro SG-5010 servo and need to figure out how to incorporate this servo into this code. (The issue is that I don’t know how to convert the angle into PWM.

//Control a Parallax Servo without using the Arduino library

int servo = 7;

int angle;
int pwm;

void setup()
{
  pinMode(servo, OUTPUT);
}

void loop ()
{
  for (angle = 0; angle <= 140; angle += 5)  {
    servoPulse(servo, angle);  }
  for (angle = 140; angle >= 0; angle -= 5)  {
    servoPulse(servo, angle);  }
}
  
void servoPulse (int servo, int angle)
{
  pwm = (angle*11) + 500;      // Convert angle to microseconds
  digitalWrite(servo, HIGH);
  delayMicroseconds(pwm);
  digitalWrite(servo, LOW);
  delay(50);                   // Refresh cycle of servo
}

The issue is that I don't know how to convert the angle into PWM

sp. "PPM". The angle thing is just a convenience - servo travel varies form model to model, so you need to calibrate it yourself. I'd modify the sketch to print the pulse length, add a pot to control the pulse length, and see what the angular travel is for a given rnage of pulse lengths.

I am curious. Why not use the library?

I'm trying to do the same thing. The reason that I can't use the servo library is that I'm using the sound shield from adafruit and there is a conflict when I try to #include servo.h. Here's the compile error:

/var/folders/rW/rWvoTHZWF+iF1HuGiixILU+++TI/-Tmp-/build5300156778023286889.tmp/S ervo/Servo.cpp.o: In function `__vector_11':

/Applications/Arduino.app/Contents/Resources/Java/hardware/libraries/Servo/Servo .cpp:104: multiple definition of `__vector_11'

/var/folders/rW/rWvoTHZWF+iF1HuGiixILU+++TI/-Tmp-/build5300156778023286889.tmp/A F_Wave/wave.cpp.o:/Applications/Arduino.app/Contents/Resources/Java/hardware/lib raries/AF_Wave/wave.cpp:33: first defined here

So I'm trying to build this without the servo library. Regarding the first response, what is a, "pot?" Also, just want to make sure I'm clear, by "pulse length" you're referring to the value of pwm in the code, right? Lastly, will the servo hold the last input value indefinitely, or will it return to zero after "digitalWRite(servo, LOW);"

Thanks.

Regarding the first response, what is a, "pot?" Also, just want to make sure I'm clear, by "pulse length" you're referring to the value of pwm in the code, right?

pot == potentiometer (variable potential divider)

We don't use PWM to control servos, we use PPM, but the width of the controlling pulse is roughly 1 to 2ms, repeating every 20ms. (yes, I know you coulld do that with PWM, but just don't, OK?

Lastly, will the servo hold the last input value indefinitely, or will it return to zero after "digitalWRite(servo, LOW);"

Well, since the last pulse was only 1/50th of a second ago, the answer must be no. However, "indefinitely" could be a long time, and without any driving pulses and a shaft load, the servo could move.