I'm actually very surprised nobody has made a Li-ion/LiFePoâ‚„ fuel gauge using Padauk
PMS171B yet. It is programmable using the Free PDK toolchain, and costs only about 8 cents in sets of five at LCSC. A Diodes Inc. AZ431AN-ATRE1 2.5V 0.4% shunt voltage reference costs three cents. If you run the PMS171B from the Li cell voltage, the reference will read 152 at 4.2V, 156 at 4.1V, 168 at 3.8V, 183 at 3.5V, 200 at 3.2V, and 213 at 3.0V; i.e. 8-bit ADC reading
N corresponds to voltage 640/
N volts. (Resolution 0.025V around 4V, 0.016V around 3V.)
With three output pins, you can light one of four different LEDs at a time (without high-Z), each with their own resistor. You can do PWM/PDM to compensate for the varying current if running from the 3.0V - 4.2V Li cell voltage. In the SO8 package, there is even a pin free for doing a low-side switch using an N-channel MOSFET, so that a button press turns connects the circuit to the real negative rail, with the MCU pin keeping it connected so it can turn itself off after a time limit, not consuming any current while turned off.
Or, you can run the circuit off the shunt voltage reference, and measure the cell voltage for example via an opamp that subtracts the 2.5V from the cell voltage, yielding about 0.01V precision. The LEDs would then run off the 2.5V I/O levels, too.
By my count, the components for that would cost under 30 cents in sets of five at LCSC, add maybe 15-20 cents for a suitable TI RRIO opamp for the more precise version.
I like the idea of having the most significant LED blink at say 2 Hz, with duty cycle indicating the fraction (or constant on time, but off time and period varies).
With the SO-16 version of PMS171B, you could even use a two-segment LED display to show the charge as percent between 00 and 99.