analogReadResolution

dear friend ,

void setup() {
// open a serial connection
Serial.begin(9600);
}

void loop() {
// read the input on A0 at default resolution (10 bits)
// and send it out the serial connection
analogReadResolution(10);
Serial.print("ADC 10-bit (default) : ");
Serial.print(analogRead(A0));

// change the resolution to 12 bits and read A0
analogReadResolution(12);
Serial.print(", 12-bit : ");
Serial.print(analogRead(A0));

// change the resolution to 16 bits and read A0
analogReadResolution(16);
Serial.print(", 16-bit : ");
Serial.print(analogRead(A0));

// change the resolution to 8 bits and read A0
analogReadResolution(8);
Serial.print(", 8-bit : ");
Serial.println(analogRead(A0));

// a little delay to not hog serial monitor
delay(100);
}

this code is not working. how i learn analogReadResolution function. i need good reason for this one.

and then how i get bit value 2^n . may be i need long bits through 16bit

this code is not working.

Yes it is.
It might not be doing what you want but it is working.

See:-
http://arduino.cc/en/Reference/AnalogReadResolution

It says:-
analogReadResolution() is an extension of the Analog API for the Arduino Due.

So are you using a Due?

It says:-
If you set the analogReadResolution() value to a value higher than your board's capabilities, the Arduino will only report back at its highest resolution padding the extra bits with zeros.

For example: using the Due with analogReadResolution(16) will give you an approximated 16-bit number with the first 12 bits containing the real ADC reading and the last 4 bits padded with zeros.

Hi,
How is it not working?
Have you put a constant voltage on A0?
Have you got the Serial Monitor set on 9600?

Tom..... :slight_smile:
And you are using a Due?