2011-10-09 16:06:19 -04:00
|
|
|
//
|
2013-08-17 09:44:20 -04:00
|
|
|
// FILE: Average.ino
|
|
|
|
// AUTHOR: Rob dot Tillaart at gmail dot com
|
2017-07-31 15:40:26 -04:00
|
|
|
// VERSION: 0.3
|
2011-10-09 16:06:19 -04:00
|
|
|
// PURPOSE: Sample sketch for statistic library Arduino
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "Statistic.h"
|
|
|
|
|
2013-08-17 09:44:20 -04:00
|
|
|
Statistic myStats;
|
2011-10-09 16:06:19 -04:00
|
|
|
|
2017-07-31 15:40:26 -04:00
|
|
|
uint32_t start;
|
|
|
|
uint32_t stop;
|
|
|
|
|
2013-08-17 09:44:20 -04:00
|
|
|
void setup(void)
|
2011-10-09 16:06:19 -04:00
|
|
|
{
|
2017-07-31 15:40:26 -04:00
|
|
|
Serial.begin(115200);
|
|
|
|
Serial.println(__FILE__);
|
2013-08-17 09:44:20 -04:00
|
|
|
Serial.print("Demo Statistics lib ");
|
2017-07-31 15:40:26 -04:00
|
|
|
Serial.println(STATISTIC_LIB_VERSION);
|
2011-10-09 16:06:19 -04:00
|
|
|
myStats.clear(); //explicitly start clean
|
2017-07-31 15:40:26 -04:00
|
|
|
start = millis();
|
2011-10-09 16:06:19 -04:00
|
|
|
}
|
|
|
|
|
2013-08-17 09:44:20 -04:00
|
|
|
void loop(void)
|
2011-10-09 16:06:19 -04:00
|
|
|
{
|
|
|
|
long rn = random(0, 9999);
|
2017-07-31 15:40:26 -04:00
|
|
|
myStats.add(rn / 100.0 + 1);
|
2011-10-09 16:06:19 -04:00
|
|
|
if (myStats.count() == 10000)
|
|
|
|
{
|
2017-07-31 15:40:26 -04:00
|
|
|
stop = millis();
|
|
|
|
Serial.print(" Count: ");
|
2013-08-17 09:44:20 -04:00
|
|
|
Serial.println(myStats.count());
|
2017-07-31 15:40:26 -04:00
|
|
|
Serial.print(" Min: ");
|
|
|
|
Serial.println(myStats.minimum(), 4);
|
|
|
|
Serial.print(" Max: ");
|
|
|
|
Serial.println(myStats.maximum(), 4);
|
|
|
|
Serial.print(" Average: ");
|
2011-10-09 16:06:19 -04:00
|
|
|
Serial.println(myStats.average(), 4);
|
2013-08-17 09:44:20 -04:00
|
|
|
// uncomment in Statistic.h file to use stdev
|
2017-07-31 15:40:26 -04:00
|
|
|
#ifdef STAT_USE_STDEV
|
|
|
|
Serial.print(" variance: ");
|
|
|
|
Serial.println(myStats.variance(), 4);
|
2011-10-09 16:06:19 -04:00
|
|
|
Serial.print(" pop stdev: ");
|
|
|
|
Serial.println(myStats.pop_stdev(), 4);
|
2017-07-31 15:40:26 -04:00
|
|
|
Serial.print(" unbias stdev: ");
|
2013-08-17 09:44:20 -04:00
|
|
|
Serial.println(myStats.unbiased_stdev(), 4);
|
2017-07-31 15:40:26 -04:00
|
|
|
#endif
|
|
|
|
Serial.print(" time(ms): ");
|
|
|
|
Serial.println(stop - start);
|
2011-10-09 16:06:19 -04:00
|
|
|
Serial.println("=====================================");
|
|
|
|
myStats.clear();
|
|
|
|
delay(1000);
|
2017-07-31 15:40:26 -04:00
|
|
|
start = millis();
|
2011-10-09 16:06:19 -04:00
|
|
|
}
|
|
|
|
}
|