mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
9cbe3bf5f9
+ added getElement() (not released 0.2.03 version) + added getSize() (not released 0.2.03 version) + added getCount() (not released 0.2.03 version) + updated keywords.txt + added memory protection if there is not enough memory to allocate. + added return NAN instead of 0 for getAverage() + reduced _size, _cnt, _idx to uint8_t + changed extensions of example code to .ino
40 lines
877 B
C++
40 lines
877 B
C++
//
|
|
// FILE: runningAverageHour.pde
|
|
// 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
|
|
//
|
|
|
|
#include "RunningAverage.h"
|
|
|
|
RunningAverage raMinute(60);
|
|
RunningAverage raHour(60);
|
|
|
|
int samples = 0;
|
|
|
|
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();
|
|
}
|
|
|
|
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);
|
|
} |