Mutila: Mouse's Utilities for Arduino
Oft-used utilities: debouncing buttons, averaging samples, and so on.
EMASonicRanger.h
1 #pragma once
2 
3 #include <stdint.h>
4 #include "SonicRanger.h"
5 
13 class EMASonicRanger : public SonicRanger {
14 public:
26  EMASonicRanger(const uint8_t trigPin, const uint8_t echoPin, const uint16_t periodMs=10, const float alpha=0.5, const uint16_t minimumRange=3);
27 
32  void begin();
33 
40  void update();
41 
45  uint16_t getRange();
46 
47 private:
48  uint16_t _periodMs;
49  float _alpha;
50  uint32_t _lastUpdated;
51  float _movingAverage;
52  uint16_t _lastSample;
53  uint16_t _minimumRange;
54 
55 };
56 
EMASonicRanger(const uint8_t trigPin, const uint8_t echoPin, const uint16_t periodMs=10, const float alpha=0.5, const uint16_t minimumRange=3)
uint16_t getRange()
SonicRanger with EMA-smoothed values.