Please help, my first CODE

am controling many servo's.
i would like to create a fuction to call whenever i want to make a move for each servo, i keep getting erro.

void move_servo_forward (char servoname, int startfrom , int moveto, int movespeed){
  for (int i = startfrom; i <= moveto; i++){
    servoname.write(i);
    delay(movespeed);
  }
}

please tell me where is my mistake

Servoname is one character in your code, not an instance of the servo class...

Thank you for the reply,
so can you tell me please what is the correct way to use the "Servo Motor Name Variable" that has been passed in the function, down in the function body and WRITE to it ?!

do i have to declare the servoname as array ?
like char servoname[]

No you are in a compiled language the name of a variable disappear when you compile... you need to have the servo object (or a pointer to that object) as a parameter to your function...

You need to study a bit the language concepts before going further

(untested, juste typed here)

#include <Servo.h> 

Servo myservo1;
Servo myservo2;

void moveServo(Servo &s, byte angle)
{
  s.write(angle);  // set servo to angle between 0 and 180
}

void setup() 
{ 
  myservo1.attach(9);
  myservo2.attach(10);
} 

void loop() {
   moveServo(myservo1, 10);
   delay(1000);
   moveServo(myservo2, 20);
   delay(1000);
   moveServo(myservo1, 60);
   delay(1000);
   moveServo(myservo2, 90);
   delay(1000);
}

the function should take a reference to the Servo class

void move_servo_forward (Servo& srv, int startfrom , int moveto, int movespeed){
  for (int i = startfrom; i <= moveto; i++){
    srv.write(i);
    delay(movespeed);
  }
}

Thanks alot ... :slight_smile:
understanding more now ...

also just BTW...
Why do you have to have the FROM parameter?
Isn't the servo already 'somewhere'?

Calling a function with the (servo_identifier, target_position, speed); - seems more appropriate.

Hi ...
i need the from to make the loop for a smooth motion.
for i = move_from ...

ab4net:
Hi ...
i need the from to make the loop for a smooth motion.
for i = move_from ...

What @lastchancename means is that the servo knows where it is at the moment.. just do a [url=https://www.arduino.cc/en/Reference/ServoRead]servo_identifier.read()[/url] to get the start point.

Note as well that you should not do always i++ as it depends on the relative position of the end stage versus the start stage.... (ie from 30 to 120 it's i++, but from 140 to 120 it's i-- that you need)

yes you are right ...
depends on the function if it is step forward or step bacward, so once i use the ++ and another time i uses the --