comparison Potentiometer.cpp @ 1:c74204ea535c

added isStopped
author ark
date 2017-01-25 23:01 +0100
parents 4c32c9d4b94f
children a5e06e87f081
comparison
equal deleted inserted replaced
0:4c32c9d4b94f 1:c74204ea535c
22 // if value is within jitter threshold of current value, add to average 22 // if value is within jitter threshold of current value, add to average
23 if(abs(this->avg - v) <= Potentiometer::JITTER_THRESHOLD) { 23 if(abs(this->avg - v) <= Potentiometer::JITTER_THRESHOLD) {
24 if(this->num == Potentiometer::MAX_SAMPLES) { 24 if(this->num == Potentiometer::MAX_SAMPLES) {
25 this->sum -= this->avg; 25 this->sum -= this->avg;
26 this->num--; 26 this->num--;
27 this->isStopped = true;
27 } 28 }
28 this->sum += v; 29 this->sum += v;
29 this->num++; 30 this->num++;
30 this->avg = this->sum/this->num; 31 this->avg = this->sum/this->num;
31 this->value = (int)(this->avg+.5); 32 this->value = (int)(this->avg+.5);
34 else { 35 else {
35 this->value = v; 36 this->value = v;
36 this->sum = v; 37 this->sum = v;
37 this->avg = v; 38 this->avg = v;
38 this->num = 1; 39 this->num = 1;
40 this->isStopped = false;
39 } 41 }
40 #ifdef DEBUG 42 #ifdef DEBUG
41 Serial.print("pin="); 43 Serial.print("pin=");
42 Serial.print(pin); 44 Serial.print(pin);
43 Serial.print(", sum="); 45 Serial.print(", sum=");
44 Serial.print(sum); 46 Serial.print(sum);
45 Serial.print(", num="); 47 Serial.print(", num=");
46 Serial.print(num); 48 Serial.print(num);
47 Serial.print(", avg="); 49 Serial.print(", avg=");
48 Serial.println(avg); 50 Serial.println(avg);
51 Serial.print(", isStopped=");
52 Serial.println(this->isStopped);
49 #endif 53 #endif
50 } 54 }
51 55
52 56
53 void Potentiometer::update(unsigned long ms) { 57 void Potentiometer::update(unsigned long ms) {