45 lines
1.1 KiB
Arduino
Raw Normal View History

2011-10-09 22:06:19 +02:00
//
// FILE: Average.ino
// AUTHOR: Rob dot Tillaart at gmail dot com
// VERSION: 0.2
2011-10-09 22:06:19 +02:00
// PURPOSE: Sample sketch for statistic library Arduino
//
#include "Statistic.h"
Statistic myStats;
2011-10-09 22:06:19 +02:00
void setup(void)
2011-10-09 22:06:19 +02:00
{
Serial.begin(9600);
Serial.print("Demo Statistics lib ");
Serial.print(STATISTIC_LIB_VERSION);
2011-10-09 22:06:19 +02:00
myStats.clear(); //explicitly start clean
}
void loop(void)
2011-10-09 22:06:19 +02:00
{
long rn = random(0, 9999);
myStats.add(rn/100.0 + 1);
if (myStats.count() == 10000)
{
Serial.print(" Count: ");
Serial.println(myStats.count());
2011-10-09 22:06:19 +02:00
Serial.print(" Min: ");
Serial.println(myStats.minimum(),4);
Serial.print(" Max: ");
Serial.println(myStats.maximum(),4);
2011-10-09 22:06:19 +02:00
Serial.print(" Average: ");
Serial.println(myStats.average(), 4);
// uncomment in Statistic.h file to use stdev
2011-10-09 22:06:19 +02:00
#ifdef STAT_USE_STDEV
Serial.print(" pop stdev: ");
Serial.println(myStats.pop_stdev(), 4);
Serial.print(" unbias stdev: ");
Serial.println(myStats.unbiased_stdev(), 4);
2011-10-09 22:06:19 +02:00
#endif
Serial.println("=====================================");
myStats.clear();
delay(1000);
}
}