Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
updated to show the use of the new readPercent(...) functions.
  • Loading branch information
ripred authored Dec 4, 2023
1 parent 65d59ee commit 487d338
Showing 1 changed file with 33 additions and 11 deletions.
44 changes: 33 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <CPUVolt.h>
// 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:
Expand Down

0 comments on commit 487d338

Please sign in to comment.