Code help to Fill in a Frame/box

All:

Using the U8G2 library to create a frame or a box. Movement of the encoder fills/empties the box. Wondering what the appropriate method is to fill the frame dependent on a variable that may not match the width of the frame.

For example the max length of the box is 128 because of the 128x64 display. So if you have a variable that could have a value of say 10 to 100, what is the best method to extrapolate the value for filling the frame. I assume just divide the difference between the minimum and maximum and divide by 128.

So for example in the above case the difference is 90. Divide by 128 and the result is 1.42.

Easiest I suppose is to decrease the width of the box to 90 pixels and each movement of the encoder increases/decreases the fill by 1 pixel, but if I wanted to use the full 128 pixels of the display what is a better method so that is displays using the full 128 pixels. Preferably without using floats when in this example each turn of the encoder equals a value of 1.40?.

I don't need any assistance in drawing/encoder filling in the frame, just a method/process on how to solve the issue when the frame/box width does not match the spread between the variable. Curious as to what others would do?

if you have a variable that could have a value of say 10 to 100, what is the best method to extrapolate the value for filling the frame.

You could use the map() function to map the range 10-100 to 0-128

Yes, and linear algebra will do it for you as well.

Thanks for the help, will have a look at the map() function and read up on linear algebra, appreciate the assistance.

Map() did the trick :slight_smile: :slight_smile: