//...
# include <Servo.h>
Servo myServo;
// float y = ((a * x) + b) * x) + c;
const float a = (-1.0 / 180);
const float b = 2;
const float c = 0;
const int feedbackPin = 14;
void setup() {
myServo.attach(9);
Serial.begin(9600);
}
/*
y =
191.7609 + (3.237289 - 191.7609)/(1 + pow(x/92.42119), 4.382869);
d + (a - d) / (1 + pow(x / c, b));
*/
# include <math.h>
double fourPL(double x)
{
return 191.7609 + (3.237289 - 191.7609) / (1 + pow(x / 92.42119, 4.382869));
}
void loop() {
for (int x = 0; x <= 180; x++) {
float y = fourPL(x);
int servoPos = constrain(y, 0, 180);
myServo.write(servoPos);
Serial.print("x: ");
Serial.println(x);
Serial.print("servo Pos: ");
Serial.println(servoPos);
delay(10);
}
delay(500);
for (int x = 180; x > 0; x--) {
float y = fourPL(x);
int servoPos = constrain(y, 0, 180);
myServo.write(servoPos);
Serial.print("x: ");
Serial.println(x);
Serial.print("servo Pos: ");
Serial.println(servoPos);
delay(10);
}
}