Explorar o código

Update CapacitiveSensor.cpp

fixed abs() function for compilation for esp8266.
Vijay %!s(int64=2) %!d(string=hai) anos
pai
achega
cf74188c88
Modificáronse 1 ficheiros con 2 adicións e 2 borrados
  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");