This is a arduino library that helps to buffer values.
- Download the master branch from github.
- Unzip the file on the arduino library folder
- Restart the Arduino IDE
- Get buffer averages
Buffer b = Buffer(length, init);
or
Buffer b(length, init);
or
Buffer* b = new Buffer(length, init);
Buffer(length, init)
Create a new instance and clear the buffer.
length
: Buffer size, init
: Initial value
calcAverage()
Calc the buffer average and return the resultgetAverage()
Just return the buffer averagegetAt(index)
Returns the buffer value by indexempty()
Check if the buffer average is equals the initial value
fill(value)
Fill the buffer with the valueinsert(value)
Insert a new value to the buffer and callscalcAverage()
clear()
Fill the buffer with the initial value
// Create a instance of Buffer
Buffer sensorBuffer(10, 0);
// Your sensor read function
void sensorRead(){
// Get a new sensor value
int read = readSensor();
// Insert the new value on buffer
sensorBuffer.insert(read);
// Print the sensor average on Serial Monitor
Serial.println(sensorBuffer.getAverage());
}