Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
Public Member Functions | Protected Attributes | List of all members
EMAVDivSampler Class Reference

Exponential Moving Average Voltage Divider based voltage sampler. More...

#include <EMAVDivSampler.h>

Inheritance diagram for EMAVDivSampler:
Inheritance graph

Public Member Functions

 EMAVDivSampler (const uint8_t pin, const uint16_t r1KOhm, const uint16_t r2KOhm, const float vRef, const uint16_t periodMs, const float alpha)
 
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 EMASampler
 EMASampler (const uint8_t pin, const uint16_t periodMs=10, const float alpha=0.5)
 
 ~EMASampler ()
 
virtual void begin ()
 
virtual void update ()
 
virtual float average ()
 
virtual int16_t last ()
 
- 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 EMASampler
float _alpha
 alpha value used in EMA calculation
 
uint32_t _lastUpdated
 when last sample taken
 
float _movingAverage
 most recently calculated mean value
 
int16_t _lastSample
 keep the most recent sample
 
- Protected Attributes inherited from AbstractSampler
const uint8_t _pin
 pin to read data from
 
const uint16_t _periodMs
 minimum ms
 

Detailed Description

Exponential Moving Average Voltage Divider based voltage sampler.

Sampler a voltage using a voltage divider, EMA method.

Definition at line 10 of file EMAVDivSampler.h.

Constructor & Destructor Documentation

◆ EMAVDivSampler()

EMAVDivSampler::EMAVDivSampler ( const uint8_t  pin,
const uint16_t  r1KOhm,
const uint16_t  r2KOhm,
const float  vRef,
const uint16_t  periodMs,
const float  alpha 
)

Constructor

Parameters
pinthe analog input pin to read samples from
periodMsthe number of milliseconds between samples. If update() is called before periodMs has passed since the last update(), no sample will be taken.
samplesthe 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 EMAVDivSampler.cpp.


The documentation for this class was generated from the following files: