I want to retrieve an analog voltage from the ADC and display it in a bar of 10 LED's.
Its fairly common that the reading goes back and forward 1 LED and therefore I would like to add some hysteresis.
For example.
Say my average voltage is 5V and each LED (out of 10) represents 1 volt interval.
If the LED were to change from 5V to 6V the voltage would first have to reach 7V for an instant. The same if if were to change to 4V, the voltage would have to reach 3V.
I think what you might be looking for is called "smoothing" where in you take a running average of your readings so even abrupt changes will manifest subtly. There is already an excellent tutorial on this that you might want to check out.
pguerra75:
I think what you might be looking for is called "smoothing" where in you take a running average of your readings so even abrupt changes will manifest subtly. There is already an excellent tutorial on this that you might want to check out.
+/- 1 Volt hysteresis is quite large when dealing with 1 V differences in reading. I'd drop that down to maybe +/- 0.25 V. But that all depends on how stable your readings are and how much swing they have.
I'd create two parallel arrays; one containing the low thresholds for each LED and one containing the high thresholds. Then you can use an index variable to keep track of where you are.