exp()
[Math]
double exp(double x);Description
Returns the exponential value of x.
Parameters
x: The value to calculate the exponential value.
Returns
The exponential value of x.
Example Code
The code reads the value of a potentiometer connected to pin
IN and place the exponential value of x on pin
OUT.
void setup() {
pinLabel(0, "IN"); // set the label of pin 0 to "IN"
pinLabel(1, "OUT"); // set the label of pin 1 to "OUT"
pinMode(1, OUTPUT); // set pin 1 as output
pinLabel(2, "VCC"); // set the label of pin 2 to "VCC"
powerPin(2); // set pin 2 as power pin
pinLabel(3, "GND"); // set the label of pin 3 to "GND"
groundPin(3); // set pin 3 as ground pin
}
void loop() {
int val = analogRead(0); // read the value of the potentiometer
double x = map(val, 0, 1023, 0, 5); // map the value of the potentiometer from 0 to 1023 to the range of 0 to 5
double y = exp(x); // calculate the exponential value of x
int pwm = (int) map(y, 0, 148.41, 0, 1023); // map the value of y from 0 to 148.41 to 0 to 1023
analogWrite(1, pwm); // write the value of pwm to pin 1
}Notes and Warnings
The angle should be in radians. To convert the angle from degrees to
radians, multiply the angle by PI / 180.
