dose anyone happen to know if there is a way of rounding numbers in arduino ... for example in my program i need to round the anolog input form 0 (which is connected to a poteniometer ) to the nearest hundred.
Rounding can be a bit tricky, but this is one approach. Try it with a few different values of a.
int a = 523;
int b = 100*((a + 50)/100);
thank you that works fine ... im make a poteniometer controled menu system. this iwill help
be careful that your rounding formula does not have an intermediate overflow.
the way jremington does rounding is correct due to the extra () forcing the value always within int's limits.
im make a poteniometer controled menu system...
Would a rotary encoder be easier?
Just scale it down.
const int numberOfSteps = 5; int stepSelection = numberOfSteps * inputAnalogValue / 1024;
Some tweaking may be required.
Also, by the way, this is a classic example of an XY problem.