51 lines
1.0 KiB
Arduino
Raw Normal View History

2020-11-27 11:33:55 +01:00
//
// FILE: StatisticArray.ino
2021-12-28 16:28:44 +01:00
// AUTHOR: Rob Tillaart
2020-11-27 11:33:55 +01:00
// PURPOSE: Sample sketch for statistic library Arduino
2021-12-28 16:28:44 +01:00
2020-11-27 11:33:55 +01:00
#include "Statistic.h"
Statistic stats[4];
2021-12-28 16:28:44 +01:00
2020-11-27 11:33:55 +01:00
void setup(void)
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.print("Demo Statistics lib ");
Serial.println(STATISTIC_LIB_VERSION);
for (int i=0; i<4; i++)
{
stats[i].clear(); //explicitly start clean
}
}
2021-12-28 16:28:44 +01:00
2020-11-27 11:33:55 +01:00
void loop(void)
{
long rn = random(0, 9999);
int idx = random(0, 4);
stats[idx].add(rn / 100.0 + 1);
if (stats[idx].count() == 10000)
{
Serial.print("IDX: ");
Serial.println(idx);
Serial.print(" Count: ");
Serial.println(stats[idx].count());
Serial.print(" Min: ");
Serial.println(stats[idx].minimum(), 4);
Serial.print(" Max: ");
Serial.println(stats[idx].maximum(), 4);
Serial.print(" Average: ");
Serial.println(stats[idx].average(), 4);
Serial.println("=====================================");
stats[idx].clear();
}
}
2021-12-28 16:28:44 +01:00
// -- END OF FILE --