wobblyhead hg > arduino > Potentiometer
comparison Potentiometer.h @ 0:4c32c9d4b94f
initial, v1.0
| author | ark |
|---|---|
| date | 2017-01-23 01:50 +0100 |
| parents | |
| children | c74204ea535c |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:4c32c9d4b94f |
|---|---|
| 1 #ifndef Potentiometer_h | |
| 2 #define Potentiometer_h | |
| 3 | |
| 4 /** | |
| 5 utility class for dejittering a potentiometer and/or mapping its value to | |
| 6 ranges. | |
| 7 | |
| 8 (c) 2017 arkadiusz@wobblyhead.net | |
| 9 */ | |
| 10 class Potentiometer { | |
| 11 public: | |
| 12 // dejittered pot value | |
| 13 int value; | |
| 14 | |
| 15 /** | |
| 16 create an uninitialised Potentiometer. | |
| 17 setup() must be called after this to make it usable. | |
| 18 */ | |
| 19 Potentiometer(); | |
| 20 | |
| 21 /** | |
| 22 setup pod instance. | |
| 23 @param {byte} pin input pin | |
| 24 */ | |
| 25 void setup(byte pin); | |
| 26 | |
| 27 /** | |
| 28 check pin and update values. | |
| 29 */ | |
| 30 void update(); | |
| 31 | |
| 32 /** | |
| 33 check pin and update values. | |
| 34 @param {unsigned long} ms ignored | |
| 35 */ | |
| 36 void update(unsigned long ms); | |
| 37 | |
| 38 /** jitter threshold. value changes smalled than the threshold will be | |
| 39 * added to current average. value changes larger than the threshold | |
| 40 * reset the average. | |
| 41 */ | |
| 42 const unsigned long JITTER_THRESHOLD = 2; | |
| 43 | |
| 44 /** max samples for de-jittering. | |
| 45 */ | |
| 46 const int MAX_SAMPLES = 30; | |
| 47 | |
| 48 private: | |
| 49 byte pin; | |
| 50 float sum; | |
| 51 float avg; | |
| 52 int num; | |
| 53 | |
| 54 }; | |
| 55 | |
| 56 #endif |
