-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 0.4.0 increase size to 16 bit * add examples
- Loading branch information
1 parent
655b256
commit b5d01a3
Showing
13 changed files
with
258 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
// | ||
// FILE: RunningAverage.h | ||
// AUTHOR: [email protected] | ||
// VERSION: 0.3.2 | ||
// VERSION: 0.4.0 | ||
// DATE: 2016-dec-01 | ||
// PURPOSE: Arduino library to calculate the running average by means of a circular buffer | ||
// URL: https://github.com/RobTillaart/RunningAverage | ||
|
@@ -13,53 +13,58 @@ | |
#include "Arduino.h" | ||
|
||
|
||
#define RUNNINGAVERAGE_LIB_VERSION (F("0.3.2")) | ||
#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.0")) | ||
|
||
|
||
class RunningAverage | ||
{ | ||
public: | ||
explicit RunningAverage(const uint8_t size); | ||
explicit RunningAverage(const uint16_t size); | ||
~RunningAverage(); | ||
|
||
void clear(); | ||
void add(const float value) { addValue(value); }; | ||
void addValue(const float); | ||
void fillValue(const float, const uint8_t); | ||
float getValue(const uint8_t); | ||
void clear(); | ||
void add(const float value) { addValue(value); }; | ||
void addValue(const float); | ||
void fillValue(const float, const uint16_t); | ||
float getValue(const uint16_t); | ||
|
||
float getAverage(); // iterates over all elements. | ||
float getFastAverage() const; // reuses previous calculated values. | ||
float getAverage(); // iterates over all elements. | ||
float getFastAverage() const; // reuses previous calculated values. | ||
|
||
// return statistical characteristics of the running average | ||
float getStandardDeviation() const; | ||
float getStandardError() const; | ||
float getStandardDeviation() const; | ||
float getStandardError() const; | ||
|
||
// returns min/max added to the data-set since last clear | ||
float getMin() const { return _min; }; | ||
float getMax() const { return _max; }; | ||
float getMin() const { return _min; }; | ||
float getMax() const { return _max; }; | ||
|
||
// returns min/max from the values in the internal buffer | ||
float getMinInBuffer() const; | ||
float getMaxInBuffer() const; | ||
float getMinInBuffer() const; | ||
float getMaxInBuffer() const; | ||
|
||
// return true if buffer is full | ||
bool bufferIsFull() const { return _count == _size; }; | ||
bool bufferIsFull() const { return _count == _size; }; | ||
|
||
float getElement(uint8_t idx) const; | ||
float getElement(uint16_t idx) const; | ||
|
||
uint8_t getSize() const { return _size; } | ||
uint8_t getCount() const { return _count; } | ||
uint16_t getSize() const { return _size; } | ||
uint16_t getCount() const { return _count; } | ||
|
||
// use not all elements just a part from 0..partial-1 | ||
// (re)setting partial will clear the internal buffer. | ||
void setPartial(const uint16_t part = 0); // 0 ==> use all | ||
uint16_t getPartial() { return _partial; }; | ||
|
||
protected: | ||
uint8_t _size; | ||
uint8_t _count; | ||
uint8_t _index; | ||
float _sum; | ||
float* _array; | ||
float _min; | ||
float _max; | ||
uint16_t _size; | ||
uint16_t _count; | ||
uint16_t _index; | ||
uint16_t _partial; | ||
float _sum; | ||
float* _array; | ||
float _min; | ||
float _max; | ||
}; | ||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// FILE: ra_300.ino | ||
// AUTHOR: Rob Tillaart | ||
// VERSION: 0.1.0 | ||
// DATE: 2021-05-26 | ||
// | ||
// PUPROSE: demonstrate large (16 bit) buffer | ||
// | ||
|
||
#include "RunningAverage.h" | ||
|
||
RunningAverage myRA(300); | ||
int samples = 0; | ||
|
||
|
||
void setup(void) | ||
{ | ||
Serial.begin(115200); | ||
Serial.println("Demo RunningAverage lib"); | ||
Serial.print("Version: "); | ||
Serial.println(RUNNINGAVERAGE_LIB_VERSION); | ||
|
||
myRA.clear(); | ||
for (uint16_t i = 0; i < 1000; i++) | ||
{ | ||
myRA.addValue(i); | ||
Serial.print(i); | ||
Serial.print("\t"); | ||
Serial.print(myRA.getCount()); | ||
Serial.print("\t"); | ||
Serial.print(myRA.getAverage()); | ||
Serial.println(); | ||
} | ||
} | ||
|
||
|
||
void loop(void) | ||
{ | ||
} | ||
|
||
// -- END OF FILE -- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.