Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
BrownoutMode.cpp
1 #include "BrownoutMode.h"
2 
3 BrownoutMode::BrownoutMode(EMAVDivSampler& vSampler, const float vThreshLow, const float vThreshHigh) :
4  _vSampler(vSampler),
5  _vThreshLow(vThreshLow),
6  _vThreshHigh(vThreshHigh),
7  _brownedOut(true)
8 {
9 }
10 
12 {
13  _vSampler.update();
14  _DB(F("Mode::update, volts="));
15  _DBLN(_vSampler.averageVolts());
16  if (_brownedOut && _vSampler.averageVolts() > _vThreshHigh) {
17  exitBrownout();
18  _brownedOut = false;
19  } else if (!_brownedOut && _vSampler.averageVolts() < _vThreshLow) {
20  enterBrownout();
21  _brownedOut = true;
22  }
23  Mode::update();
24 }
25 
26 
27 
virtual void exitBrownout()
Definition: BrownoutMode.h:37
virtual float averageVolts()
Get the mean value in the sample set.
virtual void update()
Definition: Mode.h:85
virtual void update()
BrownoutMode(EMAVDivSampler &vSampler, const float vThreshLow, const float vThreshHigh)
Definition: BrownoutMode.cpp:3
virtual void enterBrownout()
Definition: BrownoutMode.h:31
virtual void update()
Definition: EMASampler.cpp:24
Exponential Moving Average Voltage Divider based voltage sampler.