Hello all! I have a question regarding the rounding of an integer. The integer value is taken from the voltage input of the microcontroller (ADC) and is updated every tenth of a second. The integer values ranges from 0 to 4000, but because of voltage fluctuations into the microcontroller the resulting integer value fluctuates around +/- 10 of a certain value.
What I thought about doing is rounding this value to the nearest 20. For example, if the value is 2337 then the integer value would be rounded to 2340. If the next time the integer value is updated, say to 2345, then it would be rounded down to 2340 again. This would keep the resulting integer value constant despite the value from the microcontroller's ADC fluctuating. The microcontroller can only handle integers.
I have had a wee think (and a search) but can't really think of a method of achieving this. I'm not that brilliant at programming, but I know the basics. If someone could point me in the right direction I would be very grateful. Thanks.