'''i can't call sin() and cos() in arduino i don't know how to use it
example in my code :
float theta_r=angle*(PI/180.0);
float offset= PI/4.0;
double sin=sin(theta_r-offset)X(180/3.14);
double cos=cos(theta_r-offset)X(180/3.14);
i want to try it but i receive it back "error: 'cos' cannot be used as a function"'''
I think you have to do like this:
float theta_r=angle*(PI/180.0);
float offset= PI/4.0;
double mySine=sin(theta_r-offset)X(180/3.14);
double myCosine=cos(theta_r-offset)X(180/3.14);
Welcome to the forum.
The word "sin" and "cos" are reserved by the function names. You may not create variables with those names.
You probably need a '*' instead of a 'X' to multiply with (180/3.14).
Which Arduino board do you use ?
Can you show a small but complete sketch between code tags ?
hi i'm use mega 2560
and i use "x" because in there "*" lost
void xungxoay(float goc){
int rs1, rs2;
float theta_r=goc*(PI/180.0);
float offset= PI/4.0;
double sin=sin(theta_r-offset)(180/3.14);// lỗi không tìm thấy hàm sin và cos
double cos=cos(theta_r-offset)(180/3.14);
//toc do cua dong cơ quy đổi ra xung để xoay góc x
float xung1=255cos;
float xung2=255sin;
rs1=(int)xung1;
rs2=(int)xung2;
xoay(xung1,xung2);
}
did you mean?
double mySine=sin(theta_r-offset) * (180/3.14); // * not X
double myCosine=cos(theta_r-offset) * (180/3.14); // * not X
void setup() {
Serial.begin(115200);
int angle = 20;
float theta_r = angle * (PI / 180.0);
float offset = PI / 4.0;
double mySine = sin(theta_r - offset) * (180 / 3.14);
double myCosine = cos(theta_r - offset) * (180 / 3.14);
Serial.println(mySine, 2);
Serial.println(myCosine, 2);
}
void loop() {
// put your main code here, to run repeatedly:
}
my problem is can't call sin() and cos(). i'm serach in internet my problems so i need #include <math.h> but i don't find math.h any where
The (180/3.14) conversion makes no sense. sin() and cos return a number between -1 and +1. A conversion like that would only make sense on the result of asin() and acos()
I was looking at this, sure we'll go with that
but i see sin() and cos() return radian right?
oh i'm so tired with my pj ![]()
NO! They return a unit-less number between -1 and +1. Basic trigonometry!

I do know. It doesn't.
I see what you mean, but I'm in trouble right now because I can't call the sin() and cos() functions
As request. Post your code Using Code Tags.
it is void ?
It seems that you have difficult following instructions. Code Tags.
Read this:
According to your picture, the parameter is radians, I think.
Maybe like
double mySin = sin(PI/12);
Serial.println(mySin);
I don't know, I never took this stuff in school

