asin()
[Math]
double asin(double x);
Description
Returns the principal value of the arc sine of x in radians.
Parameters
x
: The angle in radians.
Returns
The principal value of the arc sine of x in radians.
Example Code
The code reads the value of a potentiometer connected to pin
IN
and place the arc sine to the pin OUT
.
void setup() {
(0, "IN"); // set the label of pin 0 to "IN"
pinLabel(1, "OUT"); // set the label of pin 1 to "OUT"
pinLabel(1, OUTPUT); // set pin 1 as output
pinMode(2, "VCC"); // set the label of pin 2 to "VCC"
pinLabel(2); // set pin 2 as power pin
powerPin(3, "GND"); // set the label of pin 3 to "GND"
pinLabel(3); // set pin 3 as ground pin
groundPin}
void loop() {
int val = analogRead(0); // read the value of the potentiometer
double angle = map(val, 0, 1023, 0, 180); // map the value
double asinVal = asin(angle * PI / 180); // calculate the arc sine
(1, (int)map(val, -PI/2, PI/2, 0, 1024)); // map the value
analogWrite(100); // delay for 100ms
delay}
Notes and Warnings
- The angle should be in radians. To convert the angle from degrees to
radians, multiply the angle by
PI / 180
. - A domain error occurs if the argument is outside the range [-1, 1].
In this case, the function returns
NAN
.