Quote:
Originally Posted by Alan Anderson
Code:
// DISCLAIMER: THIS CODE IS UNTESTED
// declare some variables at the beginning of the code
char incount = 0; // this will count the input values being accumulated
int accumulator = 0; // this will accumulate input values
char smooth = 128; // this will hold the smoothed input value
// ....
// do this each time a new OI value is available
accumulator += (int)potval; // replace 'potval' as appropriate, e.g. p1_aux
if( incount++ == 8 ) // is this the eighth sample?
{
smooth = accumulator << 3; // a quick and sneaky way to divide by 8
incount = 0; // set to count another eight samples
accumulator = 0; // reset accumulator
}
|
Shouldn't it be:
smooth = accumulator >> 3; // a quick and sneaky way to divide by 8