Skip to content

gsvdutra/Running-Average-Library---C-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Lightweight running average for Arduino like systems

Lightweight running average library for the Arduino Platform

To use it you'll need to first define the size of your running average and the type of the class:

#define RA_SIZE N
RunningAverage<T> RA_M(RA_SIZE);

Where T can be any numeric data type and N is a positive integer.

Before using it's adiviced to fill all values with a more convenient one. To do it use the fillValue function (the default value is 0).

RA_M.fillValue(T value, int number);

It fills the average with a value the param number determines how often value is added (weight) number should preferably be between 1 and size.

Finaly the running average can be used as follow:

RA_M.addValue(T value);
T variable = RA_M.getAverage(T value);

In a pratical example:

//RunningAverage size for the encoder
#define RA_SIZE 4
RunningAverage<int> RA_M(RA_SIZE);

void setup() {
    RA_M.fillValue(0, RA_SIZE);
}

void loop() {
    Serial.println(RA_M.getAverage())
    RA_M.addValue(4);
    RA_M.addValue(4);
    RA_M.addValue(2);
    RA_M.addValue(2);
    Serial.println(RA_M.getAverage())
}

And the outputs are:

0
3

To clear the vector to it's default value use the clear() fucntion.

About

Running average library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages