setup() keeps repeating for no reason

Hey guys,

Problem is pretty much the title.
I never had such a behaviour and i'm completely clueless why i have it here.

My Code is

long m1;
long m2;
long m3;
long mav;
long minimum;
long revvolt = 0;
long zellen[0][1];
int zellenzahl=0;

void setup() {
  Serial.begin(9600);
  
  Serial.println("SETUP START");
  
  
  for (int i = 20; i <= 53; i++) {
    pinMode (i, OUTPUT);
    digitalWrite(i, LOW);
  }
  pinMode (A13, INPUT);
  pinMode (A14, INPUT);
  
  
  delay(100);
  revvolt = messen(30, A14);
  Serial.println(revvolt);
  
  delay(100);
  

  for (int i=0; i<=5; i++){
    if (messen((42+2*i), A14) >= 1000){
      zellenzahl=zellenzahl+1;
    }
  }
  
  Serial.println("");
  Serial.print("Zellenzahl:");
  Serial.println(zellenzahl);
  
  
  long zellen[zellenzahl-1][0];
  
  for (int i=0; i<=zellenzahl-1; i++){
    zellen[i][0] = messen((42+2*i), A14);
    digitalWrite((43+2*i), HIGH);
    delay(200);
    digitalWrite((43+2*i), LOW);
    Serial.print("Zelle "+String(i+1)+": ");
    Serial.println(3.292/revvolt*zellen[i][0], 3);
  }
  
  Serial.println("SETUP END");
  delay(1000);
}




void loop() {
  
  Serial.println("LOOP START"); 
  
  for (int i=0; i<=zellenzahl-1; i++){
    Serial.println("LOOP 1"); 
    zellen[i][0] = messen((42+2*i), A14);
    Serial.println("LOOP 2"); 
    Serial.print("Zelle "+String(i+1)+": ");
    Serial.println(3.292/revvolt*zellen[i][0], 3);
    delay(100);
  }
  Serial.println("LOOP END");  
}

long messen(int trigger, int messpin){
  digitalWrite(trigger, HIGH);
  delay(100);
  long wert = 0;
  for (int i = 0; i <=20 ; i++) {
    wert = wert+ analogRead(messpin);
    delay(5);
  }
  digitalWrite(trigger, LOW);
  delay(10);
  return(wert);
}

Serial Output is below.

Note how the "LOOP 1"-marker is reached, but "LOOP 2" is not.
Apparently

zellen[i][0] = messen((42+2*i), A14);

somehow restarts the setup.

SETUP START
14733

Zellenzahl:3
Zelle 1: 3.828
Zelle 2: 3.826
Zelle 3: 3.828
SETUP END
LOOP START
LOOP 1
SETUP START
14731

Zellenzahl:3
Zelle 1: 3.827
Zelle 2: 3.827
Zelle 3: 3.829
SETUP END

Why so?

Help is greatly appreciated.

zellen has zero rows of one element?
Edit: just noticed you have a second zellen array.

TheMemberFormerlyKnownAsAWOL:
zellen has zero rows of one element?
Edit: just noticed you have a second zellen array.

The 2nd zellen array is a number of rows each with zero elements, so same problem, it occupies no space and has no element [ 0 ]

I was confused because the indices start with 0 but the numer of entrys with 1 (obviously).

I changed line 7 and 42 from

long zellen[0][1];

  long zellen[zellenzahl-1][0];

to

long zellen[1][1];

  long zellen[zellenzahl][1];

the output is even more weird now, and inconsistent:

SETUP START
14934

Zellenzahl:3
Zelle 1: 3.807
Zelle 2: 3.812
Zelle 3: 3.808
SETUP END
LOOP START
LOOP 1
LOOP 2
Zelle 1: 3.805
LOOP 1
SETUP START
14869

Zellenzahl:3
Zelle 1: 3.833
Zelle 2: 3.829
Zelle 3: 3.832
SETUP END

Zellen has one row of one element, which begs the question of why it is an array at all.

zellenzahl may be as high as five, which may explain why things go a bit squirrely when you run this loop over your one element zellen array:

  for (int i=0; i<=zellenzahl-1; i++){
    zellen[i][0] = messen((42+2*i), A14);

it won't work, because in the line 42 you are using zellen array and it is visible only inside to the setup() function.
When you are in the loop() function the zellen array used is the global variable and that array only has one element and that is the problem.
I recommend you rename the line 7 for the next line

long zellen[MAX_ENTRY]; (with MAX_ENTRY as a static number for instance 3).

And comment the line 42, also when you set a value or read a value from the array use zellen[ i ] and not zellen[ i ][ 0 ], for instance:

Set its value: zellen[ i ] = 1000;
Read its value: long val = zellen[ i ];

setup() keeps repeating for no reason

You may be 100% sure there is a reason .

...R

gianafrancisco:
it won't work, because in the line 42 you are using zellen array and it is visible only inside to the setup() function.
When you are in the loop() function the zellen array used is the global variable and that array only has one element and that is the problem.

EXACTLY that was it.
Thanaks a lot!

I did it like this, because i wanted the "zellen" (cell voltage) array to only have as many entrys as the "zellenzahl" (number of cells)

now my array has 0 entrys, which actually is no problem at all.
The array is zellen*[j], because there are more entrys to come, like the difference to the minimum voltage of each cell.*
Is this a problem? Otherwise i just create multiple arrays