diff --git a/README.md b/README.md index a28bebe..0205634 100644 --- a/README.md +++ b/README.md @@ -106,3 +106,23 @@ None. ```c++ mySensor.reset(); ``` + +### getReadings() +##### Description +Returns a pointer to the integer array containing the collected data points. +##### Syntax +`getReadings();` +##### Parameters +None. +##### Returns +Pointer to an integer array. *(int\*)* +##### Example +```c++ +movingAvg foo(6); +... +int* myData; +myData = foo.getReadings(); +Serial.println(myData[0]); // first data point +Serial.println(myData[1]); // second data point +// etc. +``` \ No newline at end of file diff --git a/examples/GetReadings/GetReadings.ino b/examples/GetReadings/GetReadings.ino new file mode 100644 index 0000000..a45acdd --- /dev/null +++ b/examples/GetReadings/GetReadings.ino @@ -0,0 +1,36 @@ +// Arduino Moving Average Library +// https://github.com/JChristensen/movingAvg +// Copyright (C) 2020 by Jack Christensen and licensed under +// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html +// +// Example sketch to demonstrate retrieving the readings +// from a movingAvg object. + +#include // https://github.com/JChristensen/movingAvg + +movingAvg foo(6); + +void setup() +{ + Serial.begin(115200); + foo.begin(); + foo.reading(1); // generate some sample data + foo.reading(2); + foo.reading(3); + foo.reading(4); + //foo.reading(5); + //foo.reading(6); + + int *readings = foo.getReadings(); // returns a pointer to the readings + int n = foo.getCount(); // returns the number of readings + Serial.print("There are "); + Serial.print(n); + Serial.println(" readings:"); + for (int i=0; i maintainer=Jack Christensen sentence=A simple Arduino library for calculating moving averages. diff --git a/src/movingAvg.h b/src/movingAvg.h index bb488a9..deb0203 100644 --- a/src/movingAvg.h +++ b/src/movingAvg.h @@ -16,6 +16,7 @@ class movingAvg int getAvg(); int getCount() {return m_nbrReadings;} void reset(); + int* getReadings() {return m_readings;} private: int m_interval; // number of data points for the moving average