How can i input a inverse tangent into arduino?

I have tried to use atan into arduino but it didn't work.
it can't help me to calculate the formula and move my servo.

For example, i need to calculate
Tan x = 4 / 12

i need the angle x

then what should i input?

atan(4/12); ?

Or i need to add a library of math.h into my arduino?? =( =( =(

1 Like

Lmknss:
Or i need to add a library of math.h into my arduino?

http://arduino.cc/en/Math/H

I have tried to use atan into arduino but it didn't work.

Radian and Degree (Keep in mind) 8)

1 Like

i have read this page and i have tried to input following that instruction.

int bx= double atan2 (double __4, double __12);

it said

sketch_apr13a:17: error: expected primary-expression before 'double'
sketch_apr13a:17: error: expected ',' or ';' before 'double'

how can i fix this problem? :frowning:

sorry i just start to learn arduino =( =( =(

be aware of

  • the difference between atan() and atan2() // output range differs
  • the case then x == 0 (tan(PI/2) is undefined)
  • the result is radians.

try this

int bx = round( atan2 (4, 12) * 180/3.14159265 ); // radians to degrees and rounding

Lmknss:
int bx= double atan2 (double __4, double __12);

it said

sketch_apr13a:17: error: expected primary-expression before 'double'
sketch_apr13a:17: error: expected ',' or ';' before 'double'

how can i fix this problem? :frowning:

Error come due to syntax of above statment;
double atan2 () is a builtin function of library.

// x should be initialize before this statment 
double bx =   atan (x);

robtillaart:
be aware of

  • the difference between atan() and atan2() // output range differs
  • the case then x == 0 (tan(PI/2) is undefined)
  • the result is radians.

try this

int bx = round( atan2 (4, 12) * 180/3.14159265 ); // radians to degrees and rounding

It works! Thanks for your help XD XD XD