# New to this - Fault in Code for Robot

Alright, still relatively new to this, trying to write some modular code to operate an four-legged robot using eight servos.

Here is my code:

``````//forward and cw are positive

#include <Servo.h>

#define first_servo_pin 8
#define up 45
#define down 135
#define mid 90
#define pause 100
#define constant1 1
#define constant2 1

int original;
int epsilon = 3;
int vector;

int lookup1[4] = {1,1,1,1};
int lookup2[4] = {1,1,1,1};
int lookup3[4] = {1,1,1,1};
int lookup4[4] = {1,1,1,1};
int lookup5[4] = {1,1,1,1};

void setup()  {

for(int i = 0; i < 4; i++)  {
hip[i].attach(first_servo_pin+i);
hip[i].write(mid);
delay(pause);
}

for(int j = 0; j < 4; j++)  {
knee[j].attach(first_servo_pin+4+j);
knee[j].write(down);
delay(pause);
}

}

void loop()  {

translate(100);
rotate(90);

}

void moveLeg(tag,epsilon)  {
knee[tag].write(up);
delay(pause);
hip[tag].write(original + epsilon);
delay(pause);
knee[tag].write(down);
delay(pause);
}

void moveBody(unitVector)  {
for(int i = 0; i < epsilon; i++)  {          //distance
for(int j = 0; j < 4; j++)  {              //four legs
moveLeg(lookup5(j),unitVector*epsilon);
}
}
}

void translate(vector)  {
for(int i = 0; i < abs(vector)*constant1; i++)  {  //distance
for(int j = 0; j < 3; j=j+2)  {                  //switch between sets
for(int k = 0; k < 2; k++)  {                  //switch between legs
moveLeg(lookup1(j+k),2*epsilon);
}
moveBody(lookup2(j+k));
}
}
}

void rotate(angle)  {
for(int i = 0; i < abs(angle)*constant2; i++)  {  //angle
for(int j = 0; j < 3; j=j+2)  {                 //switch between sets
for(int k = 0; k < 2; k++)  {                 //switch between legs
moveLeg(lookup3(j+k),2*epsilon);
}
moveBody(lookup4(j+k));
}
}
}
``````

Note - Most numbers are only placeholders and will be different in the final configuration.

… and here is my fault:

error: variable or field ‘moveLeg’ declared void In function ‘void setup()’:
In function ‘void loop()’:
At global scope:

Think I’m missing something fairly simple but I don’t have enough experience / practice to see it quickly. Any suggestions?

``````void moveLeg(tag,epsilon)
``````

You haven't told the compiler what types the variables are. The compiler needs to know this, to ensure that the caller supplies the right type of arguments.

Ok, changed the code so that all variables were defined at the very beginning and still get the same error, any other suggestions?

You need to declare `hip` and `knee` :)

Global variables declared at the top of the sketch, and function variables, declared in the function statement are completely independent.

You still need to tell the function what type of variable tag is and what type of variable epsilon is.