Hardware Reference
In-Depth Information
Trigonometry calculations on the Arduino are accomplished with sin() ,
cos(), and tan() .
sin()
sin() calculates the sine of an angle in radians. The result is returned as a
double between -1 and 1.
result = sin(angle);
Here, the angle parameter is a float , the angle in radians, and the function
returns a double ; the sine of the angle.
cos()
cos() calculates the cosine of an angle in radians. The result is returned as a
double between -1 and 1.
result = cos(angle);
Once again, this function takes a single parameter, a float , the angle in
radians, and returns a double .
tan()
tan() calculates the tangent of an angle in radians. The result is returned as
a double .
result = cos(angle);
Constants
The functions used to calculate the sine, cosine, and tangent all require the angle
to be expressed in radians, which isn't always what you have. Converting degrees
to radians and back again is a simple mathematical formula, but the Arduino
goes one step further, proposing two constants; DEG_TO_RAD , and RAD_TO_DEG :
deg = rad * RAD_TO_DEG;
rad = deg * DEG_TO_RAD;
Arduino also has another constant; PI , which of course is the familiar con-
stant for π.
Interrupts
Interrupts are a way to respond immediately to external signals without having
to spend a lot of time looking for changes.
 
Search WWH ::




Custom Search