Hey all. This was originally going to be a possible bug report, but I just figured out the issue, and thought I'd share it.
I have this program with a lot of data, and i at first was initializing it as in the following program:
void setup() {
for( int i=2 ; i<13 ; i++ )
{
pinMode(i, OUTPUT);
}
}
void loop() {
delay( 100 );
digitalWrite( 3, HIGH );
delay( 100 );
digitalWrite( 3, LOW );
}
int myData[349]= {
/* 348 - LED blinks */
/* 349 - LED doing strange things */
/* 350 - LED is solid */
/* 400 - LED doesn't blink */
/* change that to [20][20] to make the Arduino NG not work */
/* change that to static int pattern[ whatever]; and it works fine */
};
I found that the data at around the above sizes causes the above issues.
However, If i define the data as "static", it works great!
static int myData[4096] = {
/* data list */
}
It works just fine.
I'm assuming that this will store the data in ROM space rather than limited RAM space.
Just a heads up for any of you who might be seeing issues with large data sizes.
I'm assuming that this will store the data in ROM space rather than limited RAM space.
I doubt it, since this would mean you can't modify the values, which means they'd be constant.
A static variable is one whose memory is allocated once per program execution. An automatica variable (which is the default and opposite of static) gets its memory allocated each time the function in which it is declared is called.
In practice on most systems static variables are allocated on the heap, while automatic variables are on the stack. I have no idea how gcc allocates memory on the Atmel, but you may be seeing something caused by the automatic (i.e., non-static) variable overflowing the stack.
Pretty much. You might also want to change the type, if, for example, you're storing ints instead of chars, which would mean you need to initialize the array with something like: { 10, 20, 30, 40 } instead of "Foo".