Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
src
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
42
~EMASampler
() {;}
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
;
72
float
_movingAverage
;
73
int16_t
_lastSample
;
74
75
};
76
EMASampler::_alpha
float _alpha
alpha value used in EMA calculation
Definition:
EMASampler.h:70
EMASampler::average
virtual float average()
Definition:
EMASampler.h:63
EMASampler::~EMASampler
~EMASampler()
Definition:
EMASampler.h:42
EMASampler::_movingAverage
float _movingAverage
most recently calculated mean value
Definition:
EMASampler.h:72
EMASampler::_lastUpdated
uint32_t _lastUpdated
when last sample taken
Definition:
EMASampler.h:71
AbstractSampler::pin
uint8_t pin()
Accessor for the pin which is geting read from.
Definition:
AbstractSampler.h:34
EMASampler
Exponential Moving Average (EMA) analog pin sampler.
Definition:
EMASampler.h:28
EMASampler::EMASampler
EMASampler(const uint8_t pin, const uint16_t periodMs=10, const float alpha=0.5)
Definition:
EMASampler.cpp:6
EMASampler::_lastSample
int16_t _lastSample
keep the most recent sample
Definition:
EMASampler.h:73
EMASampler::last
virtual int16_t last()
Definition:
EMASampler.h:67
EMASampler::begin
virtual void begin()
Definition:
EMASampler.cpp:15
EMASampler::update
virtual void update()
Definition:
EMASampler.cpp:24
AbstractSampler
Base class for analog pin sampling classes.
Definition:
AbstractSampler.h:12
Generated by
1.8.15