mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
63 lines
1.2 KiB
Arduino
63 lines
1.2 KiB
Arduino
|
//
|
||
|
// FILE: ra_getAverageSubset.ino
|
||
|
// AUTHOR: Rob Tillaart
|
||
|
// DATE: 2012-12-30
|
||
|
// PUPROSE: show working of runningAverage
|
||
|
|
||
|
|
||
|
#include "RunningAverage.h"
|
||
|
|
||
|
RunningAverage myRA(10);
|
||
|
int samples = 0;
|
||
|
|
||
|
|
||
|
void setup(void)
|
||
|
{
|
||
|
Serial.begin(115200);
|
||
|
Serial.println("Demo RunningAverage lib");
|
||
|
Serial.print("Version: ");
|
||
|
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
|
||
|
myRA.clear(); // explicitly start clean
|
||
|
|
||
|
for (int i = 0; i < 20; i++)
|
||
|
{
|
||
|
myRA.addValue(i);
|
||
|
}
|
||
|
Serial.println();
|
||
|
Serial.print(myRA.getAverage(), 3);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(myRA.getAverageSubset(0, 5), 3);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(myRA.getAverageSubset(3, 5), 3);
|
||
|
Serial.print("\t");
|
||
|
Serial.println(myRA.getAverageSubset(5, 5), 3);
|
||
|
Serial.println();
|
||
|
delay(10000);
|
||
|
|
||
|
myRA.clear(); // explicitly start clean
|
||
|
}
|
||
|
|
||
|
|
||
|
void loop(void)
|
||
|
{
|
||
|
long rn = random(0, 1000);
|
||
|
myRA.addValue(rn * 0.001);
|
||
|
samples++;
|
||
|
Serial.print(samples);
|
||
|
Serial.print("\t");
|
||
|
Serial.print(100 * myRA.getAverage(), 3);
|
||
|
Serial.print("\t");
|
||
|
Serial.println(100 * myRA.getAverageSubset(5, 5), 3);
|
||
|
|
||
|
if (samples == 300)
|
||
|
{
|
||
|
samples = 0;
|
||
|
myRA.clear();
|
||
|
Serial.println();
|
||
|
}
|
||
|
delay(10);
|
||
|
}
|
||
|
|
||
|
|
||
|
// -- END OF FILE --
|