Problem with FOR loops

1

I'm trying to simplify the content of the movement function () to two loops, but doing it in loops does not do anything to me. My code is as follows:

int movimimiento(){
    mueve_servo(&patas[1][1], mov_home[1][1]);
    mueve_servo(&patas[1][2], mov_home[1][2]);
    mueve_servo(&patas[3][1], mov_home[3][1]);
    mueve_servo(&patas[3][2], mov_home[3][2]);
    mueve_servo(&patas[5][1], mov_home[5][1]);
    mueve_servo(&patas[5][2], mov_home[5][2]);

}

My question is how I can put the content in the form of loops to reduce code and especially that it has the same functionality. I have done the following, but it does not do anything to me:

int numero_patas[3] = {1, 3, 5};
int num_art[2] = {1, 2};

for(int pata = 0; pata < sizeof(numero_patas); pata++) {
    for(int art = 0; art < sizeof(num_art); art++) {
        mueve_servo(&patas[numero_patas[pata]][num_art[art]], mov_home[numero_patas[pata]][num_art[art]]);
    }
}

Thank you very much !!

    
asked by jose 11.11.2018 в 22:00
source

1 answer

3

You are doing something simple in a totally complicated way.

You do not need an array (and two less) to make that for.

You only have to move your variables the number of necessary steps, and cut where appropriate.

It would be something like this:

for(int pata = 1; pata < 7; pata=pata+2) {
    for(int art = 1; art < 3; art++) {
        mueve_servo(&patas[pata][art], mov_home[pata][art]);
    }
}
    
answered by 11.11.2018 в 22:46