Go Down

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


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(){

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

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.


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.


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

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131