Hi Alex
Not that it will save you a lot of RAM in this example, but when constructing the average rather than storing 5 values you could use a cumulative moving average. It would reduce your sampling loop to this:
void loop() {
AvgRPM = 0; // reset the average
for (int i = 1; i <= 5; i++) { // note the subtle change from 0 up to 1 up
rpmcount = 0;
delay(100); // let the interrupts do their thing
AvgRPM = AvgRPM + (rpmcount - AvgRPM)/i;
}
// rest of loop()
}
The beauty of it is it's simple to tune it to any number of samples you like, without needing to change structure of the code or number of variables or size of the memory footprint. Simply change the upper limit of your for() loop.
Normal caveats about untested code, insufficient caffeine etc apply ![]()
More info on how that's derived at Moving average - Wikipedia
Cheers ! Geoff
edit: peterH's fix applied