I am trying to take some of my routines and make them into header files. I haven't done that in ages.
- I want to get the analogReadResolution set for the device
- I want to read the battery Voltage using the built in resistor divider {if there is one for that device-- will need a lookup table i imagine)
Rough draft follows:
```cpp
#define versionInfo "See if i can remember how to write & use a .h file"
// ~9 (A7) is the Feather Vbatt measure pin. DO NOT USE IT FOR ANOTHER INPUT!
// battery pin -- ** this will eventually need to be set for each platform with a lookup table ***
#define VBatPin A7 // THIS IS THE D9 BATTERY CHECK PIN - has built in 100k/100k divider (called D9, ~9, PA07, Y5, or AIN7 on schematics) note: AIN7 doesn't work!
// analog Voltage ref-- again, needs to be set by device. Manual override could have it passed to the routine as an option or just make fuinction invalid
#define Vref 3.35 // volatge reference for AD converter
#define battDeadVoltage 3.55 // we need to flush the SD Card and post flashing light- ADC inflates below 3.5V. Data loss is impending.
#define battLowVoltage 3.7 // This value sets where the warning starts for Vbat being low
#define battFull_ChargeVoltage 4.17 // If there is a 3.7V lithium battery, if the value is higher than this it is probably not connected to the M0
float getBatValue(void) {
// built-in double-100K resistor divider on the BAT pin connected to {D9 (a.k.a analog #7 A7) on Feather}.
// Read built in divider voltage, double it --> battery voltage.
// Actual Feather Calculated Battery Value including ADC error as Vcc drops
// warning: nonlinearity with low Vbatt: 3.75 V --> 3.75 V, 3.50 V --> 3.50 V, 3.25 V --> 3.42 V, 3.00 V --> 3.43 V
float measuredVBat = 0;
// NEED SOMETHING TO GET ANALOG READ RESOLUTION HERE
measuredVBat = analogRead(VBatPin) * 2 * Vref / (pow(2, getAnalogReadResolution()) - 1); // resistor-divider is Vbat/2, so double it. Mult by ref Voltage (3.3). Convert AD -> Voltage
return (measuredVBat);
} // end getBatValue
double getAnalogReadResolution(void) {
double readResolution = 0; // pow by definition wants a double, even though we know this is an analog (bits) value
// code here to read the analog read resolution and return it to calling program
return (readResolution);
}