#include <Servo.h>
Servo myServo; // create servo object to control the servo
int potPin = A0; // analog input pin for the potentiometer
int angleMin = 0; // minimum angle (in degrees)
int angleMax = 30; // maximum angle (in degrees)
int vMin = 512; // voltage output of the potentiometer at minimum angle
int vMax = 600; // voltage output of the potentiometer at maximum angle
int powerMin = 50; // minimum power (in percent)
int powerMax = 100; // maximum power (in percent)
void setup() {
myServo.attach(9); // attaches the servo on pin 9 to the servo object
Serial.begin(9600); // initialize serial communication
}
void loop() {
// read the voltage output of the potentiometer
int vPot = analogRead(potPin);
// calculate the corresponding angle using the calibration formula
float angle = (vPot - vMin) * (angleMax - angleMin) / (vMax - vMin) + angleMin;
// calculate the corresponding power using a linear mapping from angle to power
int power = map(angle, angleMin, angleMax, powerMin, powerMax);
// constrain the power to a range between 0 and 100
power = constrain(power, 0, 100);
// set the power to the motor using the servo
myServo.writeMicroseconds(map(power, 0, 100, 1000, 2000));
// print the angle and power to the serial monitor
Serial.print("Angle: ");
Serial.print(angle);
Serial.print(" degrees, Power: ");
Serial.print(power);
Serial.println("%");
delay(100); // wait for a short time before reading the potentiometer again
}