Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).


## [0.4.8] - 2025-08-01
- add array example
- update examples
- minor edits

## [0.4.7] - 2024-08-12
- Fix #33, add **float getCoefficientOfVariation()**
- update readme.md
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2012-2024 Rob Tillaart
Copyright (c) 2012-2025 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,18 @@ update the internal **\_sum**.
- https://github.com/RobTillaart/Correlation
- https://github.com/RobTillaart/GST - Golden standard test metrics
- https://github.com/RobTillaart/Histogram
- https://github.com/RobTillaart/infiniteAverage
- https://github.com/RobTillaart/RunningAngle
- https://github.com/RobTillaart/RunningAverage
- https://github.com/RobTillaart/RunningMedian
- https://github.com/RobTillaart/statHelpers - combinations & permutations
- https://github.com/RobTillaart/Statistic
- https://github.com/RobTillaart/Student

For printing floats in scientific or engineering format

https://github.com/RobTillaart/printHelpers


## Interface

Expand Down
2 changes: 1 addition & 1 deletion RunningAverage.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: RunningAverage.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.4.7
// VERSION: 0.4.8
// DATE: 2011-01-30
// PURPOSE: Arduino library to calculate the running average by means of a circular buffer
// URL: https://github.com/RobTillaart/RunningAverage
Expand Down
4 changes: 2 additions & 2 deletions RunningAverage.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: RunningAverage.h
// AUTHOR: Rob Tillaart
// VERSION: 0.4.7
// VERSION: 0.4.8
// DATE: 2011-01-30
// PURPOSE: Arduino library to calculate the running average by means of a circular buffer
// URL: https://github.com/RobTillaart/RunningAverage
Expand All @@ -14,7 +14,7 @@
#include "Arduino.h"


#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.7"))
#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.8"))


class RunningAverage
Expand Down
15 changes: 10 additions & 5 deletions examples/fillValue/fillValue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,36 @@ int samples = 0;
uint32_t start, stop;


void setup(void)
void setup(void)
{
Serial.begin(115200);
Serial.print("Demo RunningAverage lib - fillValue ");
Serial.println();
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

for (int i = 0; i < 15; i++)
{
measure_duration(i);
}

Serial.println();
}


void loop(void)
void loop(void)
{
long rn = random(0, 100);
myRA.addValue(rn / 100.0);
samples++;
Serial.print("Running Average: ");
Serial.println(myRA.getAverage(), 4);

if (samples == 300)
{
samples = 0;
Expand Down
6 changes: 5 additions & 1 deletion examples/ra_300/ra_300.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);

Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

for (uint16_t i = 0; i < 1000; i++)
{
myRA.addValue(i);
Expand Down
4 changes: 4 additions & 0 deletions examples/ra_300_last/ra_300_last.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

for (uint16_t i = 0; i < 1000; i++)
{
myRA.addValue(i); // random(1000)); (i);
Expand Down
3 changes: 2 additions & 1 deletion examples/ra_FastAverageTest/ra_FastAverageTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

// explicitly start clean
myRA.clear();
Expand Down Expand Up @@ -58,7 +59,7 @@ void measure_duration()
Serial.println(stop - start);
delay(10);
Serial.println();
}
}


void test(long n)
Expand Down
6 changes: 5 additions & 1 deletion examples/ra_MinMaxBufferTest/ra_MinMaxBufferTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
myRA.clear(); // explicitly start clean
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

Serial.println("\nCNT\tMIN\tMINBUF\tMAX\tMAXBUF");
}
Expand Down
6 changes: 5 additions & 1 deletion examples/ra_MinMaxTest/ra_MinMaxTest.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
myRA.clear(); // explicitly start clean
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

Serial.println("\nCNT\tMIN\tAVG\tMAX");
}
Expand Down
90 changes: 90 additions & 0 deletions examples/ra_array/ra_array.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// FILE: ra_array.ino
// AUTHOR: Rob Tillaart
// PURPOSE: show working of an array of runningAverage objects
// URL: https://github.com/RobTillaart/RunningAverage


#include "RunningAverage.h"

// note the differrent sizes.
//RunningAverage RA0(10);
//RunningAverage RA1(15);
//RunningAverage RA2(20);
//RunningAverage RA3(10);
//RunningAverage RA4(15);
//RunningAverage RA5(20);
//
//RunningAverage RA[6] = { RA0, RA1, RA2, RA3, RA4, RA5 };

RunningAverage RA[6] =
{
RunningAverage(5),
RunningAverage(7),
RunningAverage(9),
RunningAverage(11),
RunningAverage(13),
RunningAverage(15),
};

uint32_t samples = 0;


void setup(void)
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

// explicitly start clean
for (int i = 0; i < 6; i++)
{
RA[i].clear();
}

// check different sizes.
for (int i = 0; i < 6; i++)
{
Serial.print('\t');
Serial.print(RA[i].getSize());
}
Serial.println();
}


void loop(void)
{
// read 6 ADC's
for (int i = 0; i < 6; i++)
{
int value = analogRead(A0 + i);
// optional conversion here
RA[i].addValue(value);
//Serial.print(value);
//Serial.print("\t");
}
//Serial.println();

// print a separator every 20 lines
if (samples % 20 == 0)
{
Serial.println("\n");
}
samples++;

Serial.print(samples);
for (int i = 0; i < 6; i++)
{
Serial.print('\t');
Serial.print(RA[i].getAverage(), 2);
}
Serial.println();

delay(50);
}


// -- END OF FILE --
4 changes: 4 additions & 0 deletions examples/ra_fillValue_test/ra_fillValue_test.ino
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

for (int i = 0; i < 15; i++)
{
Expand Down
5 changes: 4 additions & 1 deletion examples/ra_getAverageSubset/ra_getAverageSubset.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

myRA.clear(); // explicitly start clean
delay(10);
// explicitly start clean
myRA.clear();

for (int i = 0; i < 20; i++)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

myRA.clear(); // explicitly start clean
delay(10);
// explicitly start clean
myRA.clear();

for (int i = 0; i < 10; i++)
{
Expand Down
6 changes: 5 additions & 1 deletion examples/ra_getValue/ra_getValue.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
myRA.clear(); // explicitly start clean
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();
}


Expand Down
12 changes: 7 additions & 5 deletions examples/ra_hour/ra_hour.ino
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// FILE: runningAverageHour.ino
// AUTHOR: Rob Tillaart
// DATE: 2012-12-30
// PURPOSE: show working of runningAverage per hour
// PURPOSE: show working of runningAverage per hour
// in 2 steps - last minute + last hour
// 3 or more steps also possible
// URL: https://github.com/RobTillaart/RunningAverage
Expand All @@ -17,26 +17,28 @@ RunningAverage raHour(60);
int samples = 0;


void setup(void)
void setup(void)
{
Serial.begin(115200);
Serial.println();
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

raHour.clear();
raMinute.clear();
}


void loop(void)
void loop(void)
{
long rn = random(0, 100);
raMinute.addValue(rn);
samples++;

if (samples % 60 == 0) raHour.addValue(raMinute.getAverage());

Serial.print(" raMinute: ");
Serial.print(raMinute.getAverage(), 4);
Serial.print(" raHour: ");
Expand Down
4 changes: 4 additions & 0 deletions examples/ra_partial/ra_partial.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@ void setup(void)
Serial.println(__FILE__);
Serial.print("RUNNINGAVERAGE_LIB_VERSION: ");
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

delay(10);
// explicitly start clean
myRA.clear();

for (uint16_t i = 0; i < 30; i++)
{
myRA.addValue(i);
Expand Down
4 changes: 3 additions & 1 deletion examples/ra_performance/ra_performance.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ void setup(void)
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
Serial.println();

myRA.clear(); // explicitly start clean
delay(10);
// explicitly start clean
myRA.clear();

for (int i = 0; i < 10; i++)
{
Expand Down
Loading