Comparing Array values

Hi all, In my code i have setup an empty array called Val that is 72 bits long. I am then taking readings from a lidar distance sensor and using the for loop feeding this into each element of the array. once all the elements have been filled the process just starts again and the new lidar readings are fed into the array elements.

for(int j = 0; j <= 71; j++){
  // Take one TF Mini distance measurement
  uint16_t dist = tfmini.getDistance();
  uint16_t strength = tfmini.getRecentSignalStrength();

  // Display the measurement
  Serial.print(dist);
  Serial.print(" cm      sigstr: ");
  Serial.println(strength);
  int val[72];
  val[j] = dist;
  Serial.print(j);
  Serial.print(" num     value: ");
  Serial.println(val[j]);

I would like to compare the current element value to the new one and if there is a reduction do X but if theres an increase do Y.

Any suggestions?

Thanks

Like this ?

uint16_t oldVal[72], Val[72];
for (int i = 0; i < 72; i++) {
  oldVal[i] = Val[i];
  uint16_t dist = tfmini.getDistance();
  uint16_t strength = tfmini.getRecentSignalStrength();

  // Display the measurement
  Serial.print(dist);
  Serial.print(" cm      sigstr: ");
  Serial.println(strength);
  Val[i] = dist;
  Serial.print(i);
  Serial.print(" num     value: ");
  Serial.println(Val[i]);

  if (oldVal[i] > Val[i]) {
    // do X
  } else if (oldVal[i] < Val[i]) {
    // do Y
  }
}

Yeah that seems to do the trick thanks.
I was thinking way to complicated :slight_smile: