#include<math.h>
#include<Servo.h>
Servo servoa;
Servo servob;
int x;
int y;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
servoa.attach(3);
servob.attach(5);
Serial.println("Enter x: ");
while (!Serial.available()) {
// Wait for data to be available
}
delay(100); // Delay for stability
x = Serial.parseInt(); // Read the first integer
// Clear any remaining characters in the Serial buffer
while (Serial.available()) {
Serial.read();
}
// Prompt the user to enter the second integer
Serial.println("Enter y: ");
while (!Serial.available()) {
// Wait for data to be available
}
delay(100); // Delay for stability
y = Serial.parseInt(); // Read the second integer
angle(x,y);
}
void angle(double x,double y)
{
double l=sqrt(x*x+y*y);
double phi=atan(y/x)*(180/3.1415);
double theta=acos((l/2)/4)*(180/3.1415);
double A=phi+theta;
double B=180-2*theta;
show(A,B);
}
void show(double A,double B)
{
if(A<0)
{
A=180+A;
Serial.print("A value :");
Serial.println(A);
servoa.write(A);
}
else{
Serial.print("A value :");
Serial.println(A);
servoa.write(A);
}
if(B<0)
{
B=180+B;
Serial.print("B value :");
Serial.println(B);
servob.write(B);
}
else{
Serial.print("B value :");
Serial.println(B);
servob.write(B);
}
}
void loop() {
}