Flaw in code and I can't find it?

Are you absolutely sure this is where the error is flagged?
Since this code builds absolutely fine for me I'm pretty sure you have some other code that fails instead.

BTW, in your calculation

You have an off-by-one error.
You'd need to divide by 4095 since the maximum reading of the ADC would be 4095.
For a full amplitude signal the division should result in a factor of 1 but 4095 / 4096 will not give you that.

Also a slight reorder of that calculation will make it slightly shorter and also more "precise"

avg[sensor] = (3.3 * sum) / (NUMBER_SAMPLES * 4095);
1 Like