-
-
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.
* add getAverageLast(n), getMinInBufferLast(n), getMaxInBufferLast(n) * update keywords.txt * update unit test * update readme.md
- Loading branch information
1 parent
ac5f0b1
commit 58cddba
Showing
9 changed files
with
225 additions
and
22 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
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.4.0 | ||
// VERSION: 0.4.1 | ||
// 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,7 +13,7 @@ | |
#include "Arduino.h" | ||
|
||
|
||
#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.0")) | ||
#define RUNNINGAVERAGE_LIB_VERSION (F("0.4.1")) | ||
|
||
|
||
class RunningAverage | ||
|
@@ -56,6 +56,15 @@ class RunningAverage | |
void setPartial(const uint16_t partial = 0); // 0 ==> use all | ||
uint16_t getPartial() { return _partial; }; | ||
|
||
|
||
// get some stats from the last count additions. | ||
float getAverageLast(uint16_t count); | ||
float getMinInBufferLast(uint16_t count); | ||
float getMaxInBufferLast(uint16_t count); | ||
|
||
|
||
|
||
|
||
protected: | ||
uint16_t _size; | ||
uint16_t _count; | ||
|
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,59 @@ | ||
// | ||
// 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); // random(1000)); (i); | ||
// Serial.print(i); | ||
// Serial.print("\t"); | ||
// Serial.print(myRA.getCount()); | ||
// Serial.print("\t"); | ||
// Serial.print(myRA.getAverage()); | ||
// Serial.println(); | ||
} | ||
|
||
Serial.println(); | ||
for (uint16_t i = 1; i < 1000; i++) | ||
{ | ||
Serial.print(i); | ||
Serial.print("\t"); | ||
Serial.print(myRA.getMinInBufferLast(i)); | ||
Serial.print("\t"); | ||
Serial.print(myRA.getAverageLast(i)); | ||
Serial.print("\t"); | ||
Serial.print(myRA.getMaxInBufferLast(i)); | ||
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
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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
name=RunningAverage | ||
version=0.4.0 | ||
version=0.4.1 | ||
author=Rob Tillaart <[email protected]> | ||
maintainer=Rob Tillaart <[email protected]> | ||
sentence=The library stores the last N individual values in a circular buffer to calculate the running average. | ||
|
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