rounding off analog values

Hello,

How does the Arduino Due round of the analog values to digital numbers.

I use the following equation ADC=Vi*4095/Vref

A possible reading can be ADC=2,223*4095/3,3=2758,54

What would the digital number be in this case 2758 or 2759?

Kind regards,

Ideally, it should be whatever is closest.

A quick-scan through the [u]ATSAM datasheet[/u] tells me the tolerance is more than +/- 1 -count anyway. :wink:

roundedValue = (int)(value + 0.5);

igorv1234:
A possible reading can be ADC=2,223*4095/3,3=2758,54

No, a reading always returns an integer, not a fraction.

The 3.3volt supply, which is most likely not exactly 3.3volt, is chopped into 4096 steps.
0 - 0.8mV returns a value of 0.
0.8 - 1.6mV returns a value of 1.
etc.
Leo..