problem excuting this problem

#include <Servo.h>

Servo servo1;
Servo servo2;
Servo servo3
Servo servo4;

void setup()
{
servo1.attach(7);
servo2.attach(6);
servo3.attach(5);
servo4.attach(4);

}

void loop()
{
goto_forward();
delay(1000);
goto_pick();
delay(1000);
goto_backwards();
delay(1000);
goto_keepitem();
delay(1000);
}

void goto_forward();
servo1.write(90);
delay(1000);
servo2.write(0);
delay(1000);
servo3.write(180);
delay(1000);
servo4.write(90);
delay(1000);
}
void goto_pick();
servo1.write(90);
delay(1000);
servo2.write(0);
delay(1000);
servo3.write(180);
delay(1000);
servo4.write(90);
delay(1000);
}
void goto_backwards();
servo1.write(90);
delay(1000);
servo2.write(0);
delay(1000);
servo3.write(180);
delay(1000);
servo4.write(90);
delay(1000);
}
void goto_keepitem(
servo1.write(90);
delay(1000);
servo2.write(0);
delay(1000);
servo3.write(180);
delay(1000);
servo4.write(90);
delay(1000);
}
}

Did you mean a problem executing this program? Actually, I think, compiling this program. Anyway, your function definitions are all wrong. The curly braces {} and semicolons ";" are missing or in the wrong places.

For example:

void goto_forward();

defines a function that returns nothing and does nothing. :slight_smile:

...and you should follow the forum protocol and post your code in code tags as explained here:
http://forum.arduino.cc/index.php/topic,148850.0.html

Something like that? Not tested.

#include <Servo.h>


Servo servo[ 4 ]; 

__attribute__ ((__packed__)) enum goFunction 
{ 
  goForward = 0, goPick, goBackward, goKeepItem  
}; 


void setup()
{
  byte j = 0;
  for ( byte i = 7; i > 3; i-- )
  {
    servo[ j++ ].attach( i );
  }
}


void loop()
{
  static byte fun = 0;

  go( fun++ );

  if ( fun > 3 )  fun = 0; 
}

void go( byte fn ) // they're ALL the same in your code, but fn does tell which same to do
{
    servo1.write(90);         
    delay(1000);                     
    servo2.write(0);             
    delay(1000);                   
    servo3.write(180);             
    delay(1000);
    servo4.write(90);
   delay(1000);   
}

@dhiraj421: Please edit your post, select the code, and put it between [code][/code] tags.

You can do that by hitting the “Code” button above the posting area (It looks like a scroll with < > inside it).

How to use this forum

Servo servo1;
Servo servo2;
Servo  servo3
Servo servo4;

One of these lines in not like the others. That line is wrong.

aarg:
For example:

void goto_forward();

defines a function that returns nothing and does nothing. :slight_smile:

Sorry. But that is a perfectly valid line which calls a function called goto_forward() and does not expect any return value.

Whether it is a sensible line in the context of the rest of the program, I have no idea.

...R

Robin2:
Sorry. But that is a perfectly valid line which calls a function called goto_forward() and does not expect any return value.

Whether it is a sensible line in the context of the rest of the program, I have no idea.

...R

Well, it's because it is called from loop() that I think the OP was trying to define it. Also that it's located outside loop() or setup(). Would the compiler not then see it as a function declaration? Or a body-less function is not recognized?
Sovoid doNothing();
is maybe a call, or might be a declaration, or function prototype, while:

void doNothing(){};

is (perhaps) obviously a definition due to the curly braces?
Or is it position dependant?

So why is

void goto_forward();

a call and not a function prototype?

But the bottom line, I think is just a case of careless use of curly braces.

Robin2:
Sorry. But that is a perfectly valid line which calls a function called goto_forward() and does not expect any return value.

I am not certain that you are correct about this. I would be surprised if it compiles.

well blow me down and shiver me timbers. This is syntax with which I was previously unfamiliar. I wonder what C++ thinks I am trying to say?

It's a prototype, not a function call. Consider this example - myfunc is only called once.

void setup()
{
Serial.begin(115200);
Serial.println("Start");
void myfunc();
myfunc();

}

void loop()
{
  
}

void myfunc()
{
Serial.println("Myfunc");
}

Look at the code. The syntax of that one line is a valid prototype, but it’s obvious from the surrounding code he meant that to be the declaration of a function. Replace the ; with a { and the code make a lot more sense.

Regards,
Ray L.

Find out what the compiler does with it.

void setup()
{

myfunc(); // how you call a function with no value returned

byte x = myFuncWithReturn(); // declares a variable and puts the retrned value in it

void whatTheHuh(); // confused programming that doesn't know what, but says it anyway
}

Just because it compiles doesn't mean it's right.

Robin2:

void goto_forward();

Sorry. But that is a perfectly valid line which calls a function called goto_forward() and does not expect any return value.

No, it doesn't. It's a function prototype.

I don't recall those ever being inside of functions.

It's not particularly good practice, but you can do it. It's not good practice because it looks like a programming error (PBCAK).

void setup () { }

void loop ()
  {
  void setup ();
  void loop ();
  void init ();
  }  // end of loop

That compiles. It doesn't do much. No functions are called.