code differences

I am trying to write code for a quad project (first) I am working on and am trying to figure out the best approach.I am using a SSC32 with a Mega and have but a basic understanding of how to go about it but with the vast amount of info online it tends to get out of had fast. So I guess really I found to pieces of code online and looks like they for the most part do the same thing but was wondering if one was a better way of doing it then the other or if it does not matter at all? Below are the two examples and I understand that one is using just one servo and the other is using 3.

Example 1.

void setup() {
Serial.begin(9600);
}

void loop() {
move(1, 2000, 100);
move(1, 1000, 100);
}

void move(int servo, int position, int time) {
Serial.print("#");
Serial.print(servo);
Serial.print(" P");
Serial.print(position);
Serial.print(" T");
Serial.println(time);
delay(time);
}

Example 2.

void setup() {
Serial.begin(115200);
}
void loop() {

Serial.println("#0 P750 #4 P750 #11 P750 T500");
delay(1000);
Serial.println("#0 P2200 #4 P1500 #11 P2200 T500");
delay(1000);
}

Example 2 uses hard coded values, maybe a test case of what you'd expect of the first code modified for 3 servos.
By itself it is useless. Whereas example 1 allows a function to be called with different values.

Neither code does really anything apart from write text to the serial output.

What is it you want to achieve,
move servos?
print output to serial?
something else?

I am trying to move servo's and I am able to do that but just trying to figure what way is the better way.I have a quad that I am trying to make walk and the first thing I want to be able to do is just have it walk straight.Currently I have 3 servos per leg and it has been slow going so I am looking for any advice or tips.

The two examples may produce similar output but they do it in different ways.

Example 1 uses a function to output the data. The function can be used from anywhere in the program and different values can be passed to it so it can be used to achieve different results at different times and could, for instance, be called from a for loop to produce a series of actions.

Example 2 uses hard coded values which will be the same every time. Each movement would need to be coded explicitly and could not be changed by changing a variable, such as in a for loop.

Using a function that takes parameters is, therefore, the preferred way to code this.

well what would example 1 look like if it was 3 servos?

This is my interpretation of how commands are sent to the servos.

void loop() {
move(1, 2000, 100);  //servo 1 to position 2000 in time 100
move(2, 1000, 150);  //servo 2 to position 1000 in time 150
move(3, 1500, 220);  //servo 3 to position 1500 in time 220
}

I assume that there is a device at the other end of the serial link that is receiving the commands, interpreting them and passing them on to the servos. Have you got such a device ?

Yeah I have 12 servos connected to the ssc32 servo controller on a quad I am trying to build. The whole thing is a little daunting because my programming skill's are non existent, I do have a basic understanding but thats about it. So the code you posted is all that would need to be added for 3 servos and would work for 12, say for example?

I think I might have deleted some of my comments here :frowning:

The principle will work for as many servos as the receiving device can support but whichever method you use bear in mind that the calls to the function will happen in a sequence and not all at the same time. It is up to the receiving device to interpret and act on the commands appropriately.