Volume Conversion
RicardoSiqueira
Posts: 373
I am trying to convert a volume range from 0 to 255 to 0 to100. My goal is to display a volume percent in a text box next to a bargraph. The 0 to 255 works fine for the bargraph, but for the text box I am using ((LEVEL.VALUE * 100)/255). It works, but the problem is the decimal value resulted from the division. It throws off the volume feedback smooth ramping. Sometimes you have to press the button 3 times to move to the next percent value. For example 128*100/255 = 50.19. Any suggestions? Thanks.
Ricardo
Ricardo
0
Comments
You also need to consider how many volume steps you need. 25 or 30 seems to be plenty for a typical system, although you may be limited by the range mentioned above. And as you mentioned, you need 2 or 3 bumps on 0..255 to get 1 bump on 0..100.
So 0..255 and 0..100 may not be what you want; maybe you need 25 levels which are hard-coded to send 25..49%, or 20 levels coded to send 30..69%
Here are my general-purpose conversion functions:
You would call this function like so for the conversion you requested:
To use my suggestions above, you would code like this:
Just want to mention that you also have the option to you enter $P% as the text for the bargraph at design time and the percent will be written in the bargraph in real-time automatically. No math or unnecessary SEND_COMMAND traffic needed.
I'll keep that in mind though if ever I need to do similar on a larger display.