wobblyhead hg > arduino > Potentiometer
view Potentiometer.h @ 6:4e32bc18a7f7 default tip
adjusted jitter threshold, added ignore heuristic
| author | ark |
|---|---|
| date | 2017-07-03 00:24 +0200 |
| parents | ea44b28e12ab |
| children |
line wrap: on
line source
#ifndef Potentiometer_h #define Potentiometer_h /** utility class for dejittering a potentiometer and/or mapping its value to ranges. (c) 2017 arkadiusz@wobblyhead.net */ class Potentiometer { public: // dejittered pot value int value; // flag, if true the pot is not moving bool isStopped; /** create an uninitialised Potentiometer. setup() must be called after this to make it usable. */ Potentiometer(); /** setup or reset pot instance. @param {byte} pin input pin */ void setup(byte pin); /** check pin and update values. */ void update(); /** check pin and update values. @param {unsigned long} ms ignored */ void update(unsigned long ms); /** jitter threshold. value changes smalled than the threshold will be * added to current average. value changes larger than the threshold * reset the average. */ const unsigned long JITTER_THRESHOLD = 15; /** max samples for de-jittering. */ const int MAX_SAMPLES = 20; private: byte pin; float sum; float avg; int num; bool ignore; }; #endif
