Go Down

Topic: Array? (Read 524 times) previous topic - next topic

hsj

Nov 27, 2006, 03:33 pm Last Edit: Nov 27, 2006, 03:45 pm by hsj Reason: 1
I want to read pin values and put them in a "buffer". My program is like this:

int buffer[361] = 0;
void setup()
{...}
void loop()
{
  for(int i=0;i<361;i++)
    {
         buffer=analogRead(pinNumber);
     }
...
}

But it seems the values can not be written into the array, and some members of the array even have very absurd values. If I output the values of the pins directly then everything is fine. The problem is that they can't be written into the array.

neurascenic

Your only reading one pin at a time. and placing it into your array.  then advancing your array.

You would need a more sophisticated loop within a loop and add the values of each pin according to their position.

Or better yet, read all pins at once and place that value into your array.

Follow the link to read all pins at once  (actually the register to where they lay)

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1160606668

ñ

mellis

You might try removing the = 0 from the line declaring the array, or replacing it with = { 0 } .  Otherwise, you might try making the array smaller, as it's possible there's not enough RAM for that many elements.

Go Up