function for servo movement

when I use the direct servo functions in the loop, all right, see below:

#include <Servo.h>
Servo direcao;

void setup() {
direcao.attach(3);
}

void loop() {
direcao.write(90);
delay(4000);
direcao.write(120);
delay(4000);
direcao.write(90);
delay(4000);
direcao.write(60);
delay(4000);
direcao.write(90);
delay(4000);
}

but if I put in a function (below) does not work, what's wrong?

#include <Servo.h>
Servo direcao;

void move(){
direcao.write(90);
delay(2000);
direcao.write(120);
delay(2000);
direcao.write(90);
delay(2000);
direcao.write(60);
delay(2000);
direcao.write(90);
delay(2000);}

void setup() {
direcao.attach(3);
}

void loop() {
void move();
}

Explain what you are trying to get the servo to do.

only to move between the angles 60 - 90 - 120 degrees ....

This

void loop() {
  void move();
}

should be

void loop() {
     move();
}

When you put void before the function name it tells the compiler that you are defining a new function.

...R

thank you very much

Actually it is not a new function definition, its a function prototype, telling the compiler
that there is somewhere a function called move, not defining it nor calling it.

A function definition looks like:

void foo ()
{
}

A function prototype looks like:

void foo () ;

A function call looks like:

  foo () ;

Function calls always have to be inside another function definition, prototypes are normally at
top level but can be locally scoped (ie inside a function definition)

MarkT:
Actually it is not a new function definition, its a function prototype, telling the compiler
that there is somewhere a function called move, not defining it nor calling it.

Thanks Mark.
That explains why the compiler did not complain - I had been wondering about that.

...R

Erase void, before move(),

When you write void move();, compiler thinks that you declare sth to move() function. In other words, void is the declaring command of a function as @MarkT's Reply #5 (and Reply #3). To use the function, you just write the function name with brackets in loop. In your code, program takes move() function as blank. That's why compiler sees no problem. It is a logic error.

So compiler does its job :slight_smile:

Regards.

eXXonWaldez:
In other words, void is the declaring command of a function.

I guess you missed @MarkT's Reply #5 (and Reply #3).

...R

Robin2:
I guess you missed @MarkT's Reply #5 (and Reply #3).

...R

Noted and corrected, did not notice, sorry