Change object names in functions

Hi,

How do you change object names within functions?

E.G.:

#include <Servo.h>

....

...

Servo s1;
Servo s2;

void setup()
{
s1.attach(PWM1);
s2.attach(PWM2);
}

void loop() {

moveServo1 (0, upperLimit1, lowerLimit1, timeScale1, HIGH, 1);

}

void moveServo1 (byte curve, int upperLimit, int lowerLimit, int timeScale, boolean dir, byte servo) {
int i;
if (dir == HIGH) {
for (i=lowerLimit;i<=upperLimit;i++) {
s1.writeMicroseconds(i);
if (curve == 0) {
delay(cos_curve[(i-lowerLimit)/((upperLimit-lowerLimit)/50)]/timeScale);
}
if (curve == 1) {
delay(timeScale);
}
}
}
else {
for (i=upperLimit;i>=lowerLimit;i--) {
s1.writeMicroseconds(i);
if (curve == 0) {
delay(cos_curve[(i-lowerLimit)/((upperLimit-lowerLimit)/50)]/timeScale);
}
if (curve == 1) {
delay(timeScale);
}
}
}
}

How could I change the s1 object within the moveServo1 function to e.g. s2?

I need this becaus I don not want to write X functions that look the same.

Please help!

You don't. You're already passing the servo number to the function. Use that to decide which servo object to move.

Pass the servo object by reference instead of "hard-coding" which servo to use. You can also separate the delay calculation out to another function (see example below).

unsigned long compute_delay(byte curve, int i, int timeScale)
{
  if (curve == 0)
    return cos_curve[(i-lowerLimit)/((upperLimit-lowerLimit)/50)]/timeScale;
  if (curve == 1)
    return timeScale;
}

void moveServo1 (byte curve, int upperLimit, int lowerLimit, int timeScale, boolean dir, byte servo) {
  int begin,end,c;
  if (dir == HIGH) {  
    begin = lowerLimit;
    end = upperLimit;
    c = 1;
  } else {
    begin = upperLimit;
    end = lowerLimit;
    c = -1;
  }
  for (i=begin; i!=end; i+=c) {
    s1.writeMicroseconds(i);
    delay( compute_delay(curve, i, timeScale) );
  }
}

I'll use the MegaServo lib and the suggestion for an extra time function.
=I don't know how to pass the servo object with a reference, amber...

Thanks.