Battery level indicator
What you could do with for this is hysteresis. 

Instead of simple threshold ranges (0 &lt; A &lt; B &lt; C &lt; 5) you instead need to watch the voltage over time and decide what it is doing compared with what it has done in the past.

You need to keep a record of what state the voltage is in at any one time - That is, is it in band A, B or C in the thresholds above. You then need a second set of thresholds, A1, B1 and C1.

The two thresholds overlap:



If, for example, the voltage rises from between A and B to between B1 and C1 then you switch states to the BC state.

If it falls from between B1 and C1 to between A and B then you switch to the AB state.

Basically, if the voltage rises, it needs to transition between the lower set of thresholds to the upper set of thresholds to register as a change. If it drops it has to transition between the upper set of thresholds and the lower set of thresholds to register as a change.

So, in pseudocode,

if (State == 0A &amp;&amp; Voltage &gt; A1 &amp;&amp; Voltage &lt; B1)
    State = AB
    Turn on LED 1

if (State == AB &amp;&amp; Voltage &gt; B1 &amp;&amp; Voltage &lt; C1)
    State = BC
    Turn on LED 2

if (State == BC &amp;&amp; Voltage &gt; C1)
    State = C5
    Turn on LED 3

if (State == BC &amp;&amp; Voltage &lt; B &amp;&amp; Voltage &gt; A) 
    State = AB
    Turn on LED 2

if (State == AB &amp;&amp; Voltage &lt; A) 
    State = 0A
    Turn on LED 1

if (State == C5 &amp;&amp; Voltage &lt; C &amp;&amp; Voltage &gt; B) 
    State = BC
    Turn off all LEDs


It's up to you to decide what a good level of separation is suitable for your system.