https://github.com/daviinacio/arduino-buffer
Buffer library to arduino
https://github.com/daviinacio/arduino-buffer
arduino-library cpp cpp-lib utils-lib
Last synced: about 11 hours ago
JSON representation
Buffer library to arduino
- Host: GitHub
- URL: https://github.com/daviinacio/arduino-buffer
- Owner: daviinacio
- License: mit
- Created: 2019-03-31T23:26:38.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-04-03T13:46:24.000Z (about 6 years ago)
- Last Synced: 2025-10-29T16:42:37.647Z (8 months ago)
- Topics: arduino-library, cpp, cpp-lib, utils-lib
- Language: C++
- Size: 4.36 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Arduino Buffer
This is a arduino library that helps to buffer values.
## Instalation
1. Download [the master branch](https://github.com/daviinacio/arduino-buffer/archive/master.zip) from github.
2. Unzip the file on the arduino library folder
3. Restart the Arduino IDE
## Features
- Get buffer averages
## Getting Started
### Create buffer instance
```C++
Buffer b = Buffer(length, init);
```
or
```C++
Buffer b(length, init);
```
or
```C++
Buffer* b = new Buffer(length, init);
```
### Constructor
`Buffer(length, init)` Create a new instance and clear the buffer.
`length`: Buffer size, `init`: Initial value
### Getters
- `calcAverage()` Calc the buffer average and return the result
- `getAverage()` Just return the buffer average
- `getAt(index)` Returns the buffer value by index
- `empty()` Check if the buffer average is equals the initial value
### Setters
- `fill(value)` Fill the buffer with the value
- `insert(value)` Insert a new value to the buffer and calls `calcAverage()`
- `clear()` Fill the buffer with the initial value
## Example
```C++
// 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());
}
```