CapacitiveSensor
CapacitiveSensor copied to clipboard
Avoid error: call of overloaded 'abs(long unsigned int)' is ambiguous…
We got compilation error when compiling for stm32 Because manipulation of long unsigned int into abs math function is ambiguous and fail with call of overloaded 'abs(long unsigned int)' is ambiguous Creating a simple function that handle the absolute result of the difference of two unsigned long will always work Regards,
This error message is caused by an ambiguous call to the abs() function in the CapacitiveSensor library's capacitiveSensor() function. The compiler is unsure which abs() function to use since there are multiple overloaded versions of abs() available in different header files.
To fix this error, you can explicitly cast the arguments to the abs() function to the desired type. In this case, you can cast total and leastTotal to long int since that is the type expected by the abs() function in the math.h library, which is the one you likely intended to use.
Replace the line:
if ( (millis() - lastCal > CS_AutocaL_Millis) && abs(total - leastTotal) < (int)(.10 * (float)leastTotal) ) {
with this line
if ( (millis() - lastCal > CS_AutocaL_Millis) && abs((long int)total - (long int)leastTotal) < (int)(.10 * (float)leastTotal) ) {
This should resolve the ambiguity and allow the code to compile successfully.