Go Down

Topic: How to use arrays with Arduino? (Read 213 times) previous topic - next topic

Wonders

May 04, 2013, 09:04 am Last Edit: May 04, 2013, 09:07 am by Wonders Reason: 1
Hello forum.

Before I posted this question (a really basic one, I am absolutely sure), I read this:
http://arduino.cc/de/Reference/Array and http://www.arduino.cc/en/Tutorial/KnightRider

The difference from what I want to do is the initialization of the array. I want to give values to the array inside a cycle, and the example shows an array being read in a cycle. What I tried to do, just to try and put the concept to work in the simplest way possible (and I can't understand why it doesn't work), was this:

Code: [Select]

int val[1000];

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

void loop(){
 val[0] = 1;
 val[1] = 5;
 val[2] = 2;
 val[5] = 10;
 Serial.print("val0 = ");
 Serial.println(val[0]);
 Serial.print("val1 = ");
 Serial.println(val[1]);
 Serial.print("val2 = ");
 Serial.println(val[2]);
 Serial.print("val5 = ");
 Serial.println(val[5]);
}


The code compiles but nothing is printed. If I comment all the array related lines then I can see val0 = val1 = val2 = val5 = val0... as expected.
Is there limitation to filling arrays at different zones of the arduino code?

Thanks in advance, I hope the details are enough.

AWOL

Using 2000 of your 2048 bytes of RAM (on a Uno) may not end well for you.
Suggest you trim it down.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Wonders

Trimmed it down to 500 and all went well. Thanks for the fast answer!

Go Up