Search code examples
c#c++cembeddedled

Regarding logical equation on my C programming


I have a situation on my C programming here and just wondering whether my solution is the correct way:

I have a LED display with particle count sensor and will show 6 digit of seven segment numbers as the count value. The sensor will give voltage input value. The input is from 0V to 10V. So the range of 0V-10V need to be shown in the display as 000000 to 999999 count.

My solution is:

Display number = Input voltage * 99999.9

For example:

Display number = 10.000*99999.9=999999

Display number = 5.500*99999.9=549999

Display number = 2.300*99999.9=229999

Is this the correct solution? I notice that I will get a lot of 9 on the display value.


Solution

  • The most usable and user friendly solution is to ignore the fact that your most significant digit is capable of displaying up to 9 and simply multiply by 10000 unless you desperately need the maxim resolution in which case simply use a scale factor of 100000 and document that your range is 0-9.99999.

    My reasoning is that it is better to either loose one digit in the accuracy across the whole range or clip just the maximum value than to have an error across the entire range.