analogWriteResolution() is an extension of the Analog API for the Arduino Due/M0/M0 Pro and Primo.
This function sets the resolution of the analogWrite() function.
It defaults to 8 bits (values between 0-255)but in Arduino Due /M0/M0 Pro is possible to set the write resolution to 12, with values between 0 and 4095 to exploit the full DAC resolution or to set the PWM signal without rolling over.
Also for the Arduino Primo, it is set to default to 8 bits, but it is possible to change it to 10 or 12 bits.
- bit: the resolution (in bits) of the values used in the analogWrite()function.
The value can range from 1 to 32. If you choose a resolution higher or lower than your board's hardware capabilities, the value used in analogWrite() will be either truncated if it's too high or padded with zeros if it's too low.
// read the input on A0 and map it to a PWM pin
// with an attached LED
int sensorValue = analogRead(A0);
Serial.print("Analog Read) : ");
// change the PWM resolution to 12 bits
// the full 12 bit resolution is only supported
// on the Due
analogWrite(11, map(sensorValue, 0, 1023, 0, 4095));
Serial.print(" , 12-bit PWM value : ");
Serial.print(map(sensorValue, 0, 1023, 0, 4095));