wobblyhead hg > arduino > Potentiometer
diff Potentiometer.h @ 0:4c32c9d4b94f
initial, v1.0
| author | ark |
|---|---|
| date | 2017-01-23 01:50 +0100 |
| parents | |
| children | c74204ea535c |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Potentiometer.h Mon Jan 23 01:50:42 2017 +0100 @@ -0,0 +1,56 @@ +#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; + + /** + create an uninitialised Potentiometer. + setup() must be called after this to make it usable. + */ + Potentiometer(); + + /** + setup pod 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 = 2; + + /** max samples for de-jittering. + */ + const int MAX_SAMPLES = 30; + + private: + byte pin; + float sum; + float avg; + int num; + +}; + +#endif
