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) );
}
}