// // FILE: hist_test.pde // AUTHOR: Rob Tillaart // DATE: 2012-12-23 // // PUPROSE: test histogram frequency // #include "histogram.h" double b[] = { 0, 100, 200, 300, 325, 350, 375, 400, 500, 600, 700, 800, 900, 1000 }; Histogram hist(14, b); unsigned long lastTime = 0; const unsigned long threshold = 500; // milliseconds, for updating display void setup() { Serial.begin(115200); Serial.print("\nHistogram version: "); Serial.println(HISTOGRAM_LIB_VERSION); } void loop() { int x = analogRead(A0); hist.add(x); // update output unsigned long now = millis(); if (now - lastTime > threshold) { lastTime = now; Serial.print(hist.count()); for (int i = 0; i < hist.size(); i++) { Serial.print("\t"); // gives percentage per bucket // Serial.print(hist.bucket(i)); Serial.print(hist.frequency(i),2); } // find quartiles Serial.print("\t"); Serial.print(hist.VAL(0.25), 2); Serial.print("\t"); Serial.print(hist.VAL(0.50), 2); Serial.print("\t"); Serial.print(hist.VAL(0.75), 2); Serial.println(); if (hist.count() > 250000UL) hist.clear(); } }