wobblyhead hg > arduino > Potentiometer
annotate Potentiometer.h @ 3:8f15fb46a050
higher jitter threshold, necesary at higher ambient temp?
| author | ark |
|---|---|
| date | 2017-06-02 21:39 +0200 |
| parents | a5e06e87f081 |
| children | ea44b28e12ab |
| rev | line source |
|---|---|
| 0 | 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; | |
| 1 | 14 |
| 15 // flag, if true the pot is not moving | |
| 16 bool isStopped; | |
| 0 | 17 |
| 18 /** | |
| 19 create an uninitialised Potentiometer. | |
| 20 setup() must be called after this to make it usable. | |
| 21 */ | |
| 22 Potentiometer(); | |
| 23 | |
| 24 /** | |
| 1 | 25 setup pot instance. |
| 0 | 26 @param {byte} pin input pin |
| 27 */ | |
| 28 void setup(byte pin); | |
| 29 | |
| 30 /** | |
| 31 check pin and update values. | |
| 32 */ | |
| 33 void update(); | |
| 34 | |
| 35 /** | |
| 36 check pin and update values. | |
| 37 @param {unsigned long} ms ignored | |
| 38 */ | |
| 39 void update(unsigned long ms); | |
| 40 | |
| 41 /** jitter threshold. value changes smalled than the threshold will be | |
| 42 * added to current average. value changes larger than the threshold | |
| 43 * reset the average. | |
| 44 */ | |
|
3
8f15fb46a050
higher jitter threshold, necesary at higher ambient temp?
ark
parents:
2
diff
changeset
|
45 const unsigned long JITTER_THRESHOLD = 3; |
| 0 | 46 |
| 47 /** max samples for de-jittering. | |
| 48 */ | |
| 2 | 49 const int MAX_SAMPLES = 20; |
| 0 | 50 |
| 51 private: | |
| 52 byte pin; | |
| 53 float sum; | |
| 54 float avg; | |
| 55 int num; | |
| 56 | |
| 57 }; | |
| 58 | |
| 59 #endif |
