-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add method to calculate shorter-term average using only a specified
- Loading branch information
1 parent
bde0db6
commit 393cc83
Showing
5 changed files
with
78 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// 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 calculating shorter term averages | ||
// from a subset of the data, using just the most recent data points. | ||
|
||
#include <movingAvg.h> // https://github.com/JChristensen/movingAvg | ||
|
||
constexpr int arraySize {30}; | ||
movingAvg foo(arraySize); | ||
|
||
void setup() | ||
{ | ||
Serial.begin(115200); | ||
foo.begin(); | ||
|
||
// generate some sample data | ||
for (int i=1; i<=arraySize; ++i) { | ||
foo.reading(i); | ||
} | ||
|
||
Serial.print("Average overall: "); | ||
Serial.println(foo.getAvg()); | ||
Serial.print("Average last 10: "); | ||
Serial.println(foo.getAvg(10)); | ||
Serial.print("Average last 3: "); | ||
Serial.println(foo.getAvg(3)); | ||
Serial.print("Average last 2: "); | ||
Serial.println(foo.getAvg(2)); | ||
Serial.print("Average last 1: "); | ||
Serial.println(foo.getAvg(1)); | ||
Serial.print("Average last 0: "); | ||
Serial.println(foo.getAvg(0)); | ||
Serial.print("Average last 30: "); | ||
Serial.println(foo.getAvg(30)); | ||
Serial.print("Average last 31: "); | ||
Serial.println(foo.getAvg(31)); | ||
} | ||
|
||
void loop() {} |
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,9 +1,9 @@ | ||
name=movingAvg | ||
version=2.2.0 | ||
version=2.3.0 | ||
author=Jack Christensen <[email protected]> | ||
maintainer=Jack Christensen <[email protected]> | ||
sentence=A simple Arduino library for calculating moving averages. | ||
paragraph=Useful for smoothing sensor readings, etc. For efficiency, the library operates in the integer domain; therefore the moving average calculation is approximate. | ||
category=Data Processing | ||
url=https://github.com/JChristensen/movingAvg | ||
architectures=avr | ||
architectures=* |
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