Skip to content

Commit

Permalink
improves documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
rlogiacco committed Jan 21, 2024
1 parent 38b830b commit dc42010
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ In reality, the relation between battery capacity and its voltage is better repr
- [Higher than 5V, activated on demand](#higher-than-5v-activated-on-demand)
- [Voltage divider ratio](#voltage-divider-ratio)
- [ADC Resolution](#adc-resolution)
- [Variable Resolution](#variable-resolution)
- [Remaining capacity approximation](#remaining-capacity-approximation)
- [Improvable](#improvable)
- [Good enough](#good-enough)
Expand Down Expand Up @@ -176,22 +175,18 @@ The *voltage divider total resistance*, made of `R1 + R2`, will determine the cu
When determining the *ratio* don't stick with the resistors nominal values, instead, if possible, use a multimeter to actually measure their resistance so to improve your results: a `4.7kΩ` resistor could easily be a `4.75kΩ` in reality!

## ADC Resolution
Starting from version `1.2.0` the library supports ADC resolutions other than the standard `10bits` of classic Arduino boards.
The library attempts to determine if the board you are building for does support a different ADC resolution and it adopts the default value for such boards, but in case your board is not supported, please:
1. verify you are using the latest version of this library
2. open an issue specifing the board you are building for and the expected ADC resolution
3. temporarily define a macro variable `ADC_RESOLUTION` in your code with the number of bits your ADC uses (eq. `#define ADC_RESOLUTION 12`) **before** importing the library header file
Starting from version `1.2.0` the library supports ADC resolutions other than the standard `10bits` of classic Arduino boards through an additional, but optional, constructor parameter named `adcBits` which obviously defaults to `10`.

So, in case your board ADC provides an ADC with a resolution higher than 10 bits, you should provide the additional parameter with the number of bits your ADC provides. In case the board has the ability to change the ADC resolution at runtime, it is your responbility to ensure the ADC resolution is properly set before each call to any of the measuring functions: `voltage` or `level`.

```cpp
#define ADC_RESOLUTION 12
#include <Battery.h>

Battery batt = Battery(3000, 4200, SENSE_PIN, 12);
```

The currently maximum supported value for the ADC resolution is `15`: specifying a value greater than that will break the library behaviour.

### Variable Resolution
Some boards support the ability to change the ADC resolution programmatically: if this is your case and your code specifies a non default value, you **must** specify the `ADC_RESOLUTION` macro variable accordingly.
## Remaining capacity approximation
The `level` available functions aim at providing an approximation of the remaining battery capacity in percentage. This is not an easy task when you want to achieve reliable values and it is something the industry of mobile devices invests a decent amount of resources.
When an accurate estimate is desireable the battery voltage is not the sole parameter you want to take into consideration:
Expand Down

0 comments on commit dc42010

Please sign in to comment.