RunningMinMax

February 2, 2026 ยท View on GitHub

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

RunningMinMax

Arduino library for a running Minimum and Maximum.

Description

Experimental

RunningMinMax stores values in a ring buffer and can return the minimum, maximum and the average of the buffer. The first implementation is not optimized.

The library can be used e.g. to have an indication for the maximum volume for a VU meter.

The library does not store timestamps of the samples (yet), that might be a function in the future.

Feedback as always welcome.

For printing floats in scientific or engineering format

https://github.com/RobTillaart/printHelpers

Interface

#include "RunningMinMax.h"

Constructor

  • RunningMinMax (const uint8_t size) Constructor, dynamically allocates memory.
  • ~RunningMinMax() Destructor.
  • uint8_t getSize() returns size of internal array.
  • uint8_t getCount() returns current used elements, getCount() <= getSize().
  • bool isFull() returns true if the internal buffer is 100% filled.

Base functions

  • clear() resets internal buffer and variables, effectively empty the buffer.
  • add(const T value) adds a new value to internal buffer, optionally replacing the oldest element if the buffer is full.
  • float getAverage() returns average of the values in the internal buffer.
  • T getMaximum() get the largest values in the buffer.
  • T getMinimum() get the smallest value in the buffer.

Performance

See performance example (version 0.2.0, UNO R3)

Typeaddminmaxavg
float10.88108108256
int32_t6.644036392
int16_t5.762832384
int8_t5.522420340

Average is expensive due to conversion to float, except for float data type. Removing (not using) the average function could reduce footprint as no float math is used elsewhere.

Future

Must

  • improve documentation.
  • test
  • template class
    • user defines type

Should

  • Stereo example
  • Array example
    • multichannel. (8 bit class needed)
    • equalizer (better example)

Could

  • investigate for optimizations.
    • cache values + dirty flag(bitmask) when add.
    • only works when reading more often than writing.
  • check for optimizations.
  • IsEmpty(), noData()?
  • extend unit tests

Wont

Support

If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.

Thank you,