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