RobTillaart / RunningAverage

Arduino library to calculate the running average by means of a circular buffer.
MIT License
53 stars 10 forks source link

ok to use this libaray for integers #14

Closed patfelst closed 2 years ago

patfelst commented 2 years ago

Hi Rob, I've been searching for a simple circular buffer that can calculate averages. My project is for a Sensirion SCD-41 carbon dioxide (CO2) sensor which returns uint16_t values. This library looks ideal. Bonus is all the other min / max functions.

Do you see any problem with me converting these to float so I can use this libary?

Thanks!

patfelst commented 2 years ago

I've had a better look at the examples now, and I can see you add ints without even type casting to float, so I think that answers my question. I'll leave this issue open in case you have any comments or things I should look out for.

RobTillaart commented 2 years ago

You can just add the data, it will be no problem. But also have a look at the runningMedian libraty as that one will handle outliers differently.

RunningAverage includes outliers in the average, runningMedian won't unless there are so many that it fills up the buffer.

patfelst commented 2 years ago

Thanks I've got it running beautifully on an ESP32. I've got 3 circular buffers, one size [12] for history of last minute of raw samples at 5 sec/sample, another size [60] for an hours worth of average of the last minute, and another size [24] for days worth of average of the last hour. This library has saved me so much time, literally coded this in just a few lines of code.

I had a look at runningMedian, but this one serves my purpose ok. I notice you have a few other arduino repositories too 😲

RobTillaart commented 2 years ago

Good to hear you got it all working. Yes been working with Arduino since 2009 or 10 and wrote quite some libs. If you are missing functionality let me know and I will look if I can add it.

Btw which sensor do you use?


update

Sensirion SCD-41 carbon dioxide (CO2)

Sorry missed that line