The analog input is reading 650~680 from a rectified signal from an LM386 and mic. This sketch is not functioning. Green is never on, blue is on, and red is flashing. I have revised this sketch many ways to make the relative LED’s go LOW without success.
This code looks like the input value and existing value are being divided by 8, added together, and the result subtracted from the existing value.
If that's the case, why not use multiplication and division. These operations are intuitively obvious, while bit shifting is not. I understand that bit shifting is faster, but the code is not easily understood, whereas R = (R * 7)/8 + I/8 is relatively easily understood.
Given that OP waits several seconds after this, I'm missing the benefit of this optimization.
If that’s the case, why not use multiplication and division
Good point - but I’m old-school from the days before optimising compilers.
When I see “(x * 7) / 8”, writing “(x - (x >> 3))” actually is more intuitive (for me)!"
True but ... now 3 decimal bits are used in the intermediate calculation of filter_reg and that decreases the digital (truncation) noise in the filter by a factor 8. A very good thing for precise things as motor control, not necessary for some other applications.
It is not about optimizing compilers, it is really about fixed point decimal calculations.
Perhaps not a direct correlation, but when the input is larger than the output, the output goes up. When the input is less than the output, the output goes down. So, the filter does seem to be working, in that it is averaging the inputs
I have seen a procedure that calls for new and old values to be compared in order to reject the odd value. Would this be a possible solution to avoid oscillating LED's out of sync?
Would a digital mic be better for out application than a simple electret? A Physical Computing circuit does not include the diodes. These came from another source. Would dropping them from the circuit be advisable?