Kaynağa Gözat

Merge pull request #46 from vks007/master

Update CapacitiveSensor.cpp
Paul Stoffregen 2 yıl önce
ebeveyn
işleme
aa0184827c
1 değiştirilmiş dosya ile 2 ekleme ve 2 silme
  1. 2 2
      CapacitiveSensor.cpp

+ 2 - 2
CapacitiveSensor.cpp

@@ -90,8 +90,8 @@ long CapacitiveSensor::capacitiveSensor(uint8_t samples)
 
 		// only calibrate if time is greater than CS_AutocaL_Millis and total is less than 10% of baseline
 		// this is an attempt to keep from calibrating when the sensor is seeing a "touched" signal
-
-		if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total  - leastTotal) < (int)(.10 * (float)leastTotal) ) {
+		unsigned long diff = (total > leastTotal) ? total - leastTotal : leastTotal - total;
+		if ( (millis() - lastCal > CS_AutocaL_Millis) && diff < (int)(.10 * (float)leastTotal) ) {
 
 			// Serial.println();               // debugging
 			// Serial.println("auto-calibrate");