With some microcontrollers you can do this "averaging out" just by changing ADC parameters, you don't even have to write the low-pass-filter code.
[1]: https://www.st.com/resource/en/application_note/an4629-adc-h...
[2]: https://en.wikipedia.org/wiki/Successive-approximation_ADC