-1
$\begingroup$

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?

$\endgroup$
  • $\begingroup$ 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"? $\endgroup$ – David Richerby May 2 '17 at 19:20
0
$\begingroup$

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}$$

$\endgroup$
  • $\begingroup$ Ahh okay thanks. I believe I studied something like this in a discrete math class a while back. $\endgroup$ – Snoop May 2 '17 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.