#include <Servo.h>
int xPin=A4,yPin=A5,swPin=2;
int xVal,yVal,swVal;
int xServo=3,yServo=5;
Servo servoX;
Servo servoY;
float angleX,angleY;
int t=1000;
void setup() {
// put your setup code here, to run once:
pinMode(xPin,INPUT);
pinMode(yPin,INPUT);
pinMode(swPin,INPUT);
digitalWrite(swPin,HIGH);
pinMode(xServo,OUTPUT);
servoX.attach(xServo);
pinMode(yServo,OUTPUT);
servoY.attach(yServo);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
xVal=analogRead(xPin);
yVal=analogRead(yPin);
swVal=digitalRead(swPin);
angleX=(180./1023.)*xVal;
angleY=(180./1023.)*yVal;
servoX.write(angleX);
servoY.write(angleY);
Serial.print("X Value = ");
Serial.print(xVal);
Serial.print(", Y Value = ");
Serial.print(yVal);
Serial.print(", Switch state: ");
Serial.println(swVal);
Serial.println();
delay(t);
}