Hi guys! I'm relatively new to the arduino platform and recently I've been trying to store the analogRead values into an array, and based on the array I aim to perform some calculations.
However I realised the values that I'm receiving from the analogRead and the values that I get from the array is different. Is it possible that I've missed out something crucial? I believe that my code to store the analog values into the array should be correct, but since I'm unable to see the same values when I access the array could this be caused by any hardware limitations of the Arduino?
I've attached my codes below and I apologize in advance if this seems to be a noob-ish question
Thanks!
const int numReadings = 500;
int threshold = 500;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int inputPin = A0;
void setup() {
Serial.begin(9600); // initialize serial communication with computer:
for (int thisReading = 0; thisReading < numReadings; thisReading++)
{
readings[thisReading] = 0; // initialize all the readings to 0:
}
}
void loop() {
readings[readIndex] = analogRead(inputPin); // read from the sensor
Serial.println(readings[readIndex]);
readIndex = readIndex + 1; // advance to the next position in the array
if (readIndex >= numReadings) // if we're at the end of the array...
{
for(int i=0;i<readIndex;i=i+1)
{
Serial.println(readings[i]);
}
readIndex = 0; // ...wrap around to the beginning:
delay(2000);
}
}