invalid conversion from 'int' to 'int*' ?!

Ok, so I wrote my question yesterday and I thought I will find a way around these twisting structures :wink: Buuuuut, another error showed up! Can anyone help me fix this?

The code is as follows:

int zadane_1[18]; 
//mapa zadanych polozen
int dir_pin[18];   
//tablica kierunku ruchu
int step_pin[18];  
// tablica stepow
int polozenie[18];  
//tablica aktualnych polozen
boolean kierunek[18]; 
//tablica wybranego kierunku
int zero[18];
//tablica polozenia poczatkowego
int komenda;

void setup() {

  dir_pin[0] = 22;
  step_pin[0]= 23;
  dir_pin[1] = 24;
  step_pin[1] = 25;
  dir_pin[2] = 26;
  step_pin[2] = 27;
  dir_pin[3] = 28;
  step_pin[3] = 29;
  dir_pin[4] = 30;
  step_pin[4] = 31;
  dir_pin[4] = 32;
  step_pin[5] = 33;
  dir_pin[6] = 34;
  step_pin[6] = 35;
  dir_pin[7] = 36;
  step_pin[7] = 37;
  dir_pin[8] = 38;
  step_pin[8] = 39;
  dir_pin[9] = 40;
  step_pin[9] = 41;
  dir_pin[10] = 42;
  step_pin[10] = 43;
  dir_pin[11] = 44;
  step_pin[11] = 45;
  dir_pin[12] = 46;
  step_pin[12] = 47;
  dir_pin[13] = 48;
  step_pin[13] = 49;
  dir_pin[14] = 50;
  step_pin[14] = 51;
  dir_pin[15] = 52;
  step_pin[15] = 53;
  dir_pin[16] = 2;
  step_pin[16] = 3;
  dir_pin[17] = 4;
  step_pin[17] = 5;

  polozenie[0]=0;
  polozenie[1]=0;
  polozenie[2]=0;
  polozenie[3]=0;
  polozenie[4]=0;
  polozenie[5]=0;
  polozenie[6]=0;
  polozenie[7]=0;
  polozenie[8]=0;
  polozenie[9]=0;
  polozenie[10]=0;
  polozenie[11]=0;
  polozenie[12]=0;
  polozenie[13]=0;
  polozenie[14]=0;
  polozenie[15]=0;
  polozenie[16]=0;
  polozenie[17]=0;

  for (int i=0;i<18;i++){
      zadane_1[i]=250;
    }

  for (int i=0;i<18;i++){
      zero[i]=0;
    }


  Serial.begin(9600);
  pinMode(dir_pin[0], OUTPUT);
  pinMode(step_pin[0], OUTPUT);
  pinMode(dir_pin[1], OUTPUT);
  pinMode(step_pin[1], OUTPUT);
  pinMode(dir_pin[2], OUTPUT);
  pinMode(step_pin[2], OUTPUT);
  pinMode(dir_pin[3], OUTPUT);
  pinMode(step_pin[3], OUTPUT);
  pinMode(dir_pin[4], OUTPUT);
  pinMode(step_pin[4], OUTPUT);
  pinMode(dir_pin[5], OUTPUT);
  pinMode(step_pin[5], OUTPUT);
  pinMode(dir_pin[6], OUTPUT);
  pinMode(step_pin[6], OUTPUT);
  pinMode(dir_pin[7], OUTPUT);
  pinMode(step_pin[7], OUTPUT);
  pinMode(dir_pin[8], OUTPUT);
  pinMode(step_pin[8], OUTPUT);
  pinMode(dir_pin[9], OUTPUT);
  pinMode(step_pin[9], OUTPUT);
  pinMode(dir_pin[10], OUTPUT);
  pinMode(step_pin[10], OUTPUT);
  pinMode(dir_pin[11], OUTPUT);
  pinMode(step_pin[11], OUTPUT);
  pinMode(dir_pin[12], OUTPUT);
  pinMode(step_pin[12], OUTPUT);
  pinMode(dir_pin[13], OUTPUT);
  pinMode(step_pin[13], OUTPUT);
  pinMode(dir_pin[14], OUTPUT);
  pinMode(step_pin[14], OUTPUT);
  pinMode(dir_pin[15], OUTPUT);
  pinMode(step_pin[15], OUTPUT);
  pinMode(dir_pin[16], OUTPUT);
  pinMode(step_pin[16], OUTPUT);
  pinMode(dir_pin[17], OUTPUT);
  pinMode(step_pin[17], OUTPUT);

  digitalWrite(dir_pin[0],LOW);
  digitalWrite(dir_pin[1],LOW); 
  digitalWrite(dir_pin[2],LOW);
  digitalWrite(dir_pin[3],LOW);
  digitalWrite(dir_pin[4],LOW);
  digitalWrite(dir_pin[5],LOW);
  digitalWrite(dir_pin[6],LOW);
  digitalWrite(dir_pin[7],LOW); 
  digitalWrite(dir_pin[8],LOW);
  digitalWrite(dir_pin[9],LOW);
  digitalWrite(dir_pin[10],LOW);
  digitalWrite(dir_pin[11],LOW);
  digitalWrite(dir_pin[12],LOW);
  digitalWrite(dir_pin[13],LOW); 
  digitalWrite(dir_pin[14],LOW);
  digitalWrite(dir_pin[15],LOW);
  digitalWrite(dir_pin[16],LOW);
  digitalWrite(dir_pin[17],LOW);

  digitalWrite(step_pin[0],LOW);
  digitalWrite(step_pin[1],LOW); 
  digitalWrite(step_pin[2],LOW);
  digitalWrite(step_pin[3],LOW);
  digitalWrite(step_pin[4],LOW);
  digitalWrite(step_pin[5],LOW);
  digitalWrite(step_pin[6],LOW);
  digitalWrite(step_pin[7],LOW); 
  digitalWrite(step_pin[8],LOW);
  digitalWrite(step_pin[9],LOW);
  digitalWrite(step_pin[10],LOW);
  digitalWrite(step_pin[11],LOW);
  digitalWrite(step_pin[12],LOW);
  digitalWrite(step_pin[13],LOW); 
  digitalWrite(step_pin[14],LOW);
  digitalWrite(step_pin[15],LOW);
  digitalWrite(step_pin[16],LOW);
  digitalWrite(step_pin[17],LOW);

}

void move_to_pos (int dir_pin[18], int step_pin [18], int polozenie[18],boolean kierunek[18], int zadane[18]){
  int i;
  for( i =0; i<18; i++){                              //ustalanie kierunku ruchu na podstawie polozenia i zadanego polozenia
      if(zadane[i]>polozenie[i]){
        digitalWrite(dir_pin[i],HIGH);
        kierunek[i]=true;}
         else{
          digitalWrite(dir_pin[i],LOW);
          kierunek[i]=false;}
}

int t=0;                                                  //znajdowanie najwiekszego elementu w tablicy zadanego polozenia
for (int i=0;i<18;i++){
    if(zadane[i]>t)
    t=zadane[i];}
    
    
    for(int k=0; i<t;k++){      //jedziemy wszystkim o tą ilość kroków
    
    for(int i=0;i<18;i++){
  digitalWrite(step_pin[i],HIGH);}
  delayMicroseconds(8000);
      for(int i=0;i<18;i++){
  if(polozenie[i]!=zadane[i]){
  digitalWrite(step_pin[i],LOW);
  if(kierunek[i]==true) polozenie[i]++;
  if(kierunek[i]==false) polozenie[i]--;}}}
  delayMicroseconds(8000);}




void loop (){
    if (Serial.available() > 0) {
    komenda = Serial.read();
	if (komenda == 'Q')
  move_to_pos (dir_pin[18],step_pin [18],polozenie[18],kierunek[18],zadane_1[18]);
	if (komenda== 'W')
	  move_to_pos (dir_pin[18],step_pin [18],polozenie[18],kierunek[18],zero[18]);}
}

The questions are:

  1. What is wrong with static arrays? Why can’t I input them in my function?
  2. Is it “legal” to input arrays with fixed sizes into function? I’m a bit confused about it… I.e can I input it like I did here:
void move_to_pos (int dir_pin[18], int step_pin [18], int polozenie[18],boolean kierunek[18], int zadane[18]){

or must I put it in empty brackets ( )?
3. How to make it work? I’m puzzled hard :confused:

  1. What is wrong with static arrays?

Nothing at all, usually

Why can't I input them in my function?

No idea, but you haven't got any static arrays.

To visualise your code better, try using the auto format tool in the IDE (ctrl-t)

   dir_pin[0] = 22;
  step_pin[0]= 23;
  dir_pin[1] = 24;
  step_pin[1] = 25;
  dir_pin[2] = 26;
  step_pin[2] = 27;
  dir_pin[3] = 28;
  step_pin[3] = 29;
  dir_pin[4] = 30;

This seems to me like an awful lot of typing, that the compiler could have done for you just as well, with less chance of making a mistake.

First, when you call a function and want to pass an array to it, you only use the array name (zadane_1), not its name and its size (zadane_1[18]). The same is true with a function: use empty brackets or make it a pointer. You call:

move_to_pos (dir_pin[18],step_pin [18],polozenie[18],kierunek[18],zadane_1[18]);

would have to be:

move_to_pos (dir_pin,step_pin,polozenie,kierunek,zadane_1);

Likewise in your function definition, the function’s signature line:

void move_to_pos (int dir_pin[18], int step_pin [18], int polozenie[18],boolean kierunek[18], int zadane[18]){

cannot be written that way. Pick one of the following:

void move_to_pos (int dir_pin[], int step_pin [], int polozenie[],boolean kierunek[], int zadane[]){
// or
void move_to_pos (int *dir_pin, int *step_pin, int *polozenie,boolean *kierunek, int *zadane){

However, since you have defined all 5 parameters with global scope, just omit them. Also, you really can simplify things if you learn how to use arrays. Notice how much simpler setup() is using arrays. I don’t know if this works, but at least it compiles.

int zadane_1[18];
//mapa zadanych polozen
int dir_pin[18];
//tablica kierunku ruchu
int step_pin[18];
// tablica stepow
int polozenie[18];
//tablica aktualnych polozen
boolean kierunek[18];
//tablica wybranego kierunku
int zero[18];
//tablica polozenia poczatkowego
int komenda;

void setup() {

  int i, j;
  j = 22;
  for (i = 0; i < 16; i++) {
    dir_pin[i] = j++;
    step_pin[i] = j++;
  }

  dir_pin[16] = 2;
  step_pin[16] = 3;
  dir_pin[17] = 4;
  step_pin[17] = 5;

  memset(polozenie, 0, sizeof(polozenie));

  for (int i = 0; i < 18; i++) {
    zadane_1[i] = 250;
  }

  for (int i = 0; i < 18; i++) {
    zero[i] = 0;
  }
  for (i = 0; i < 18; i++) {
    pinMode(dir_pin[i], OUTPUT);
    pinMode(step_pin[i], OUTPUT);
    digitalWrite(dir_pin[i], LOW);
    digitalWrite(step_pin[i], LOW);
  }

  Serial.begin(9600);

}

//void move_to_pos (int dir_pin[], int step_pin [], int polozenie[], boolean kierunek[], int zadane_1[])
void move_to_pos ()
{
  int i;
  for ( i = 0; i < 18; i++) {                         //ustalanie kierunku ruchu na podstawie polozenia i zadanego polozenia
    if (zadane_1[i] > polozenie[i]) {
      digitalWrite(dir_pin[i], HIGH);
      kierunek[i] = true;
    } else {
      digitalWrite(dir_pin[i], LOW);
      kierunek[i] = false;

    }
  }

  int t = 0;        //znajdowanie najwiekszego elementu w tablicy zadanego polozenia
  for (int i = 0; i < 18; i++) {
    if (zadane_1[i] > t)
      t = zadane_1[i];
  }


  for (int k = 0; i < t; k++) { //jedziemy wszystkim o tą ilość kroków

    for (int i = 0; i < 18; i++) {
      digitalWrite(step_pin[i], HIGH);
    }
    delayMicroseconds(8000);
    for (int i = 0; i < 18; i++) {
      if (polozenie[i] != zadane_1[i]) {
        digitalWrite(step_pin[i], LOW);
        if (kierunek[i] == true) polozenie[i]++;
        if (kierunek[i] == false) polozenie[i]--;
      }
    }
  }
  delayMicroseconds(8000);
}



void loop () {
  if (Serial.available() > 0) {
    komenda = Serial.read();
    if (komenda == 'Q')
      move_to_pos ();
    if (komenda == 'W')
      move_to_pos ();
  }
}

Thank you very much, I will look to it when I return home :slight_smile:

I know about the setup, mostly it was copy-paste, but I was going to shorten it by filling arrays with loops later. Let's say that it's an alpha version :cold_sweat:

Mainly what this function is about to do is to move 18 stepper motors from last known position to a new position from array zadane_1. There will be more arrays in the future, as more set positions will show up. So the call with completely empty brackets is not working for me, but from this point I think I will work it out.