2013-08-17 08:43:42 -04:00
|
|
|
//
|
2021-05-26 10:39:03 -04:00
|
|
|
// FILE: runningAverageTest.ino
|
2013-08-17 08:43:42 -04:00
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2012-12-30
|
2014-07-03 16:00:45 -04:00
|
|
|
// PUPROSE: show working of runningAverage
|
2013-08-17 08:43:42 -04:00
|
|
|
|
2021-05-26 10:39:03 -04:00
|
|
|
|
2013-08-17 08:43:42 -04:00
|
|
|
#include "RunningAverage.h"
|
|
|
|
|
|
|
|
RunningAverage myRA(10);
|
|
|
|
int samples = 0;
|
|
|
|
|
2021-05-26 10:39:03 -04:00
|
|
|
|
2013-08-17 08:43:42 -04:00
|
|
|
void setup(void)
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
2014-07-03 16:00:45 -04:00
|
|
|
Serial.println("Demo RunningAverage lib");
|
2013-08-17 08:43:42 -04:00
|
|
|
Serial.print("Version: ");
|
|
|
|
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
|
2014-07-03 16:00:45 -04:00
|
|
|
myRA.clear(); // explicitly start clean
|
2013-08-17 08:43:42 -04:00
|
|
|
}
|
|
|
|
|
2021-05-26 10:39:03 -04:00
|
|
|
|
2013-08-17 08:43:42 -04:00
|
|
|
void loop(void)
|
|
|
|
{
|
2014-07-03 16:00:45 -04:00
|
|
|
long rn = random(0, 1000);
|
|
|
|
myRA.addValue(rn * 0.001);
|
2013-08-17 08:43:42 -04:00
|
|
|
samples++;
|
2015-03-07 07:47:56 -05:00
|
|
|
Serial.print(samples);
|
|
|
|
Serial.print("\t Running Average: ");
|
2014-07-03 16:00:45 -04:00
|
|
|
Serial.println(myRA.getAverage(), 3);
|
2013-08-17 08:43:42 -04:00
|
|
|
|
|
|
|
if (samples == 300)
|
|
|
|
{
|
|
|
|
samples = 0;
|
2014-07-03 16:00:45 -04:00
|
|
|
myRA.clear();
|
2015-03-07 07:47:56 -05:00
|
|
|
Serial.println();
|
2013-08-17 08:43:42 -04:00
|
|
|
}
|
2015-03-07 07:47:56 -05:00
|
|
|
delay(10);
|
2021-05-26 10:39:03 -04:00
|
|
|
}
|
|
|
|
|
2021-11-24 04:03:41 -05:00
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|