Adding values in array to each other

I am not completely sure how to describe this but here we go…

I am trying to add the values from my sensor to each other. If the value is 500 (as the number of measurements) the test is confirmed since the measured value should be 1. If the value is less than 500 the test has failed.

int Sensor = 4;

for (int i = 0; i <= 500; i++)
{
int sensorVal = digitalRead(Sensor);
int A[500];
Serial.println(sensorVal);
byte arrayIndex = 0;
A[arrayIndex] = sensorVal;
This is where i want to add the values

int A[500];

This will initialise the contents of array A on each iteration of the for loop , which is not what you want

byte arrayIndex = 0;

equally, this will reset the value of the array index on each iteration of the for loop

Do you actually need to know the value of each individual reading or would just that fact that all 500 had returned a HIGH be good enough ?

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  int total = 0;
  for (int c = 0; c < 500; c++)
  {
    total +=  digitalRead(Sensor);
  }
  if (total < 500)
  {
    Serial.println("failed");
  }
  else
  {
    Serial.println("passed");
  }
}

void loop()
{
}

I just need to know that every value returned is HIGH

helenelillelund:
I just need to know that every value returned is HIGH

Then you don't need an array

See my sketch in reply #1