Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
EMASampler.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include <AbstractSampler.h>
5 
28 class EMASampler : public AbstractSampler {
29 public:
38  EMASampler(const uint8_t pin, const uint16_t periodMs=10, const float alpha=0.5);
39 
43 
50  virtual void begin();
51 
59  virtual void update();
60 
63  virtual float average() { return _movingAverage; }
64 
67  virtual int16_t last() { return _lastSample; }
68 
69 protected:
70  float _alpha;
71  uint32_t _lastUpdated;
73  int16_t _lastSample;
74 
75 };
76 
float _alpha
alpha value used in EMA calculation
Definition: EMASampler.h:70
virtual float average()
Definition: EMASampler.h:63
float _movingAverage
most recently calculated mean value
Definition: EMASampler.h:72
uint32_t _lastUpdated
when last sample taken
Definition: EMASampler.h:71
uint8_t pin()
Accessor for the pin which is geting read from.
Exponential Moving Average (EMA) analog pin sampler.
Definition: EMASampler.h:28
EMASampler(const uint8_t pin, const uint16_t periodMs=10, const float alpha=0.5)
Definition: EMASampler.cpp:6
int16_t _lastSample
keep the most recent sample
Definition: EMASampler.h:73
virtual int16_t last()
Definition: EMASampler.h:67
virtual void begin()
Definition: EMASampler.cpp:15
virtual void update()
Definition: EMASampler.cpp:24
Base class for analog pin sampling classes.