The reset of the counters in this code should be after the loop:
// Reset the counters
smoothReadingsPosition = 0;
smoothReadingsNum = 0;
// Set all the values in the array to zero. Not really needed
for (int thisReading = 0; thisReading < smoothReadingsNum; thisReading++) {
smoothReading[thisReading] = 0;
}
The reset of the counters in this code should be after the loop: