Arduino: error: 'abs' was not declared in

2019-07-11 04:56发布

问题:

I'm working on an arduino library needing the abs() function:

#include <math.h>
normTransFreq1 = abs(1.0);

Error: 'abs' was not declared in this scope

As math.h is already included in the cpp I'm entirely unsure how to fix this problem. A new install of arduino 1.5.2 didn't help.

回答1:

Just found the solution:

Including math.h is not needed for the library. Instead, Arduino.h should be included by adding the following to the header file:

#if ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif


标签: arduino