??? 03/10/09 15:03 Read: times Msg Score: +1 +1 Good Answer/Helpful |
#163301 - Happy that it works Responding to: ???'s previous message |
Glad that it worked out ok.
I managed to locate your mail in the "possibly spam" folder. How lovely it would be to live in a world without spam. About the speedbar. First off, decide what speed you require to turn on a bar. Each bar is 10mph so should you have zero bars between 0 .. 9.999 mph and then 1 bar between 10 and 19.999 etc. In that case, your computation will be (using integer truncation): 140 mph max splitted into 14 pieces for 10mph step size. Computed speed (in mph) / (140/14) = Computed speed / 10. A test: 9mph / 10 => 0 in integer arithmetics. 10mph / 10 => 1. 19mph / 10 => 1. 20mph / 10 => 2. ... 139 / 10 => 13. 140 / 10 => 14. No need for floating point or any extra tricks to keep the computation safe. All you need to to is clip the result to your maximum range, i.e. if the speed is >= 150mph you can't turn on a 15th element. One thing you may consider is if using an offset, i.e. displaying 100mph between 95 and 105 or maybe 98..107.99 instead of 100 to 109.99. In that case, just add the offset to the computed speed before dividing by 10. Another thing. Hexadecimal numbers are nice to use when working with binary objects - for example controlling bits of a port or writing a specific pattern to an SFR. But it is way easier for you to use decimal whenever you don't require a visible mapping to any two-potence. |