3 #include "EMASonicRanger.h" 9 _minimumRange(minimumRange)
16 _lastUpdated = Millis();
18 _lastSample = _movingAverage;
23 if (_periodMs == 0 || MillisSince(_lastUpdated) >= _periodMs) {
25 if (sample >= _minimumRange) {
27 _movingAverage = (_alpha*_lastSample) + ((1-_alpha)*_movingAverage);
28 _lastUpdated = Millis();
35 return _movingAverage;
EMASonicRanger(const uint8_t trigPin, const uint8_t echoPin, const uint16_t periodMs=10, const float alpha=0.5, const uint16_t minimumRange=3)