/* Get an averaged function value. 
This utility returns the average of a specified number of function values. */
static int32_t average(func callback, T arg, int M=25)
/* Get an averaged function value. 
This utility returns the average of a specified number of function values. */
static int32_t average(func callback, T arg, int M=25)
{
	float avg = 0;
	for (int j = M; j > 0; --j) {
		avg += callback(arg);
		delay_ms(5);
	}
	return (int32_t)((avg / M) + 0.5);
}