Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
|
Buffered voltage divider based voltage sampler. More...
#include <BufferedVDivSampler.h>
Public Member Functions | |
BufferedVDivSampler (const uint8_t pin, const uint16_t r1KOhm, const uint16_t r2KOhm, const float vRef=5.0, const uint16_t periodMs=10, const uint8_t samples=10) | |
virtual float | averageVolts () |
Get the mean value in the sample set. | |
virtual float | lastVolts () |
Get the most recent voltage value. | |
Public Member Functions inherited from BufferedSampler | |
BufferedSampler (const uint8_t pin, const uint16_t periodMs=10, const uint8_t samples=10) | |
~BufferedSampler () | |
virtual void | begin () |
virtual void | update () |
virtual int16_t | minimum () |
The minimum value in the sample set. | |
virtual int16_t | maximum () |
The maximum value in the sample set. | |
virtual float | average () |
Get the mean value in the sample set. | |
virtual uint8_t | count () |
virtual int16_t | last () |
Get the most recent sample value. | |
Public Member Functions inherited from AbstractSampler | |
AbstractSampler (const uint8_t pin, const uint16_t periodMs) | |
virtual | ~AbstractSampler () |
Destructor. | |
uint8_t | pin () |
Accessor for the pin which is geting read from. | |
Protected Attributes | |
uint16_t | _r1KOhm |
uint16_t | _r2KOhm |
float | _vRef |
Protected Attributes inherited from BufferedSampler | |
uint8_t | _samples |
max number of samples to keep in buffer | |
uint8_t | _idx |
index ptr (ring buffer) | |
uint8_t | _count |
number of samples in buffer | |
uint32_t | _lastUpdated |
when last sample taken | |
bool | _updated |
flag to re-calulate avg or not | |
int16_t * | _sampleData |
ring buffer for data | |
int16_t | _minimum |
most recently calculated minimum value | |
int16_t | _maximum |
most recently calculated maximum value | |
float | _mean |
most recently calculated mean value | |
Protected Attributes inherited from AbstractSampler | |
const uint8_t | _pin |
pin to read data from | |
const uint16_t | _periodMs |
minimum ms | |
Additional Inherited Members | |
Protected Member Functions inherited from BufferedSampler | |
virtual void | calculate () |
calculate avg, min, max if required | |
Buffered voltage divider based voltage sampler.
Sampler a voltage using a voltage divider, buffering values.
Definition at line 10 of file BufferedVDivSampler.h.
BufferedVDivSampler::BufferedVDivSampler | ( | const uint8_t | pin, |
const uint16_t | r1KOhm, | ||
const uint16_t | r2KOhm, | ||
const float | vRef = 5.0 , |
||
const uint16_t | periodMs = 10 , |
||
const uint8_t | samples = 10 |
||
) |
Constructor
pin | the analog input pin to read samples from |
periodMs | the number of milliseconds between samples. If update() is called before periodMs has passed since the last update(), no sample will be taken. |
samples | the number of samples to keep in the ring buffer used to calculate average(), minimum() and maximum(). |
Note: this class dynamically allocated memory for the ring buffer.
Definition at line 4 of file BufferedVDivSampler.cpp.