# Display Counting Algorithm

I am writing some firmware for a display that will take measurements and present them in real time on an LCD screen. I would like for the measurements to display as smoothly as possible... What I mean is that I am looking for a smooth animation sequence on the display, such that values don't jump from say 15.1 to 15.8... I'd like for the reading to look more natural, where maybe a sequence of values would be displayed as the value increased from 15.1 to 15.4, something like:

1. 15.1
2. 15.2
3. 15.3
4. 15.4

Before going and re-inventing the wheel, is there an algorithm that already describes what is going on here? I guess I would feel comfortable with treating these numbers as strings since that's how they will ultimately be sent to the display (as ASCII characters). Or it doesn't matter if they're treated as floating point numbers, because I can just convert them into strings before I send them to the display.

Also I'd like to add that for cases like 0.0625 to 0.1350... that the algorithm not count every single case in between the two numbers, pick maybe just 10 numbers between the two and display them.

Is there any algorithm that describes this process for the multiple cases as described above?

• I'm not really sure why you don't just display the actual value. Why waste the user's time by making them wait for the display to cycle through to the true value? Also, doesn't a moment's thought tell you that the answer is "divide the amount to be added into equal steps and then add the steps one at a time"? – David Richerby May 2 '17 at 19:20

What you are looking for is called interpolation. If you want to interpolate between values $a$ and $b$, with $s$ steps, and $i$ is your current step (going from $[0, s]$, where $i=0$ is the start value and $i=s$ is the end value), then the interpolated value is:
$$a + i\frac{b-a}{s}$$