2014-07-03 22:00:45 +02:00
|
|
|
//
|
2021-05-26 16:39:03 +02:00
|
|
|
// FILE: runningAverageHour.ino
|
2014-07-03 22:00:45 +02:00
|
|
|
// AUTHOR: Rob Tillaart
|
|
|
|
// DATE: 2012-12-30
|
|
|
|
// PUPROSE: show working of runningAverage per hour
|
|
|
|
// in 2 steps - last minute + last hour
|
|
|
|
// 3 or more steps also possible
|
|
|
|
|
2021-11-24 10:03:41 +01:00
|
|
|
|
2014-07-03 22:00:45 +02:00
|
|
|
#include "RunningAverage.h"
|
|
|
|
|
|
|
|
RunningAverage raMinute(60);
|
|
|
|
RunningAverage raHour(60);
|
|
|
|
|
|
|
|
int samples = 0;
|
|
|
|
|
2021-11-24 10:03:41 +01:00
|
|
|
|
2014-07-03 22:00:45 +02:00
|
|
|
void setup(void)
|
|
|
|
{
|
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println("Demo RunningAverage lib - average per minute & hour");
|
|
|
|
Serial.print("Version: ");
|
|
|
|
Serial.println(RUNNINGAVERAGE_LIB_VERSION);
|
|
|
|
raHour.clear();
|
|
|
|
raMinute.clear();
|
|
|
|
}
|
|
|
|
|
2021-11-24 10:03:41 +01:00
|
|
|
|
2014-07-03 22:00:45 +02:00
|
|
|
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: ");
|
|
|
|
Serial.println(raHour.getAverage(), 4);
|
2021-11-24 10:03:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -- END OF FILE --
|
|
|
|
|