Array loses data after loop


hello.
in code, set values array, when try display outside loop (the code thats enclosed /*...*/) doesn't work. when display in loop work want it.
it seems array potfixed looses data.
why that?

code: [select]


const int numofpotentiometers = 5;
const int potpins[] = {a0,a1,a2,a3,a4};

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

void loop() {
moveservo(); 
}

int moveservo() {
  int potraw[] = {};
  int potfixed[] = {};
    for(int = 0; i<numofpotentiometers; i++) {
      potraw[i] = analogread(potpins[i]);
      potfixed[i] = map(potraw[i],0,1023,0,180);
      serial.print(potfixed[i]);
      serial.print(", ");
    }
   
    delay(100);
  /*
    for(int = 0; i<numofpotentiometers; i++) {
    serial.print(potfixed[i]);
    serial.print(", ");
  }

  */
  serial.println("");
}

code: [select]
int potfixed[] = {}; reinitialise every time.

try qualifying "static"


Arduino Forum > Using Arduino > Programming Questions > Array loses data after loop


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???