|
| Battery (uint16_t minVoltage, uint16_t maxVoltage, uint8_t sensePin, uint8_t adcBits=10) |
|
void | begin (uint16_t refVoltage, float dividerRatio, mapFn_t=0) |
|
void | onDemand (uint8_t activationPin, uint8_t activationMode=LOW) |
|
uint8_t | level () |
|
uint8_t | level (uint16_t voltage) |
|
uint16_t | voltage (uint8_t delay=2) |
|
◆ Battery()
Battery::Battery |
( |
uint16_t |
minVoltage, |
|
|
uint16_t |
maxVoltage, |
|
|
uint8_t |
sensePin, |
|
|
uint8_t |
adcBits = 10 |
|
) |
| |
Creates an instance to monitor battery voltage and level. Initialization parameters depend on battery type and configuration.
- Parameters
-
minVoltage | is the voltage, expressed in millivolts, corresponding to an empty battery |
maxVoltage | is the voltage, expressed in millivolts, corresponding to a full battery |
sensePin | is the analog pin used for sensing the battery voltage |
adcBits | is the number of bits the ADC uses (defaults to 10) |
◆ begin()
void Battery::begin |
( |
uint16_t |
refVoltage, |
|
|
float |
dividerRatio, |
|
|
mapFn_t |
mapFunction = 0 |
|
) |
| |
Initializes the library by optionally setting additional parameters. To obtain the best results use a calibrated reference using the VoltageReference library or equivalent.
- Parameters
-
refVoltage | is the board reference voltage, expressed in millivolts |
dividerRatio | is the multiplier used to obtain the real battery voltage |
mapFunction | is a pointer to the function used to map the battery voltage to the remaining capacity percentage (defaults to linear mapping) |
◆ level()
uint8_t Battery::level |
( |
| ) |
|
Returns the current battery level as a number between 0 and 100, with 0 indicating an empty battery and 100 a full battery.
◆ onDemand()
void Battery::onDemand |
( |
uint8_t |
activationPin, |
|
|
uint8_t |
activationMode = LOW |
|
) |
| |
Enables on-demand activation of the sensing circuit to limit battery consumption.
- Parameters
-
activationPin | is the pin which will be turned HIGH or LOW before starting the battery sensing |
activationMode | is the optional value to set on the activationPin to enable battery sensing, defaults to LOW useful when using a resistor divider to save on battery consumption, but it can be changed to HIGH in case you are using a P-CH MOSFET or a PNP BJT |
◆ voltage()
uint16_t Battery::voltage |
( |
uint8_t |
delay = 2 | ) |
|
Returns the current battery voltage in millivolts.
- Parameters
-
delay | is the amount of milliseconds to wait to allow the ADC input voltage to stabilize (defaults to 2ms) |
◆ ON_DEMAND_DISABLE
const uint8_t Battery::ON_DEMAND_DISABLE = 0xFF |
|
static |
Activation pin value disabling the on-demand feature.
The documentation for this class was generated from the following files: