Make rotate servomotor

I am developing a project in which I must rotate a servomotor. But my idea is to pass all the values ​​in a function parameters.
I want to pass the object as parameter of the servo in the function “moveServo”.
Agradesco any contribution. :wink:

#include <Servo.h>
 
Servo myservo;   
 
void setup() { 
  myservo.attach(9);  
} 

moveServo(int servo, int grade, int time) {
  int n;
  
  for(n=0;n<=1;n++) {
    servo.write(grade);
    delay(time);
  }
}
 
void loop() { 
  moveServo(myservo,90, 1000);
}

This is error:

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
code_2:9: error: ISO C++ forbids declaration of 'moveServo' with no type
code_2.ino: In function 'int moveServo(int, int, int)':
code_2:13: error: request for member 'write' in 'servo', which is of non-class type 'int'
code_2.ino: In function 'void loop()':
code_2:19: error: cannot convert 'Servo' to 'int' for argument '1' to 'int moveServo(int, int, int)'

This should help http://forum.arduino.cc/index.php/topic,45697.0.html

hugox14:

moveServo(int servo, int grade, int time) {

int n;
 
 for(n=0;n<=1;n++) {
   servo.write(grade);
   delay(time);
 }
}

void loop() {
 moveServo(myservo,90, 1000);
}

You can see that the loop() function is prefaced by void. That means that it does not return any value. Your function also needs to be prefaced by void if it does not return a value.

…R

Your function also needs to be prefaced by void if it does not return a value.

It also needs to take the right kind of arguments. A Servo object is NOT an int.

UKHeliBob: This should help http://forum.arduino.cc/index.php/topic,45697.0.html

Thank! from Arica, Chile.