diff --git a/README.md b/README.md index e31d355..3599bf8 100644 --- a/README.md +++ b/README.md @@ -7,29 +7,51 @@ NO external parts necessary! [see this Microchip application note to learn more about the internal features used and supported to implement this feature](https://ww1.microchip.com/downloads/en/Appnotes/00002447A.pdf) +Update: Now includes support for reading the voltage as a percentage of total charge. +You can also optionally supply the voltage level that is considered to be 0% and the voltage level considered to be 100%. +This is really useful for battery-based projects! You can now specify the lower voltage level you would like to use to +indicate when the system needs charging and when it is fully charged. + Example use: # ``` + /* + * CPUVolt.ino + * + * Example Arduino sketch showing the use of the CPUVolt library. + * Updated to show the use of the new readPercent(...) methods. + * + */ #include - // We don't need a setup and a loop function so we just use a single main: - int main() { + void setup() { Serial.begin(115200); - // Measure the processor's Vcc voltage: - double volts = readVcc(); + // Read the current voltage level and convert it + // to an easier to read floating point value + float mv = readVcc() / 1000.0; - // Format it as a string to 2 decimal places: - char fstr[8]; - dtostrf(volts, 5, 2, fstr); + // Show the voltage with 2 decimal places + Serial.print("Voltage: "); + Serial.println(mv, 2); - // Display it: - Serial.print("voltage: "); - Serial.println(fstr); + // Get the voltage level as a percentage of total charge. + // You can optionally specify the voltage level to be considered + // as 100%. The default voltage is 5V if not supplied. + float pct = readPercent(/*5000*/); + Serial.print("Percent: "); + Serial.println(pct, 2); - return 0; + // You can also specify both the lower and upper voltage + // ranges to be considered what is 0% and what is 100%. + // This is really useful for battery powered projects! + pct = readPercent(2900, 4700); + Serial.print("Percent: "); + Serial.println(pct, 2); } + + void loop() { } ``` Output: