#include <Servo.h> //include servo library
#define X A0 //name analog pin A0 "X"
#define Y A1 //name analog pin A1 "Y"
#define Push 2 //name pin 2 "Push"
#define Servo1 9 //naming pin 9 Servo1
#define Servo2 10 //naming pin 10 servo2
int xpos; //declaring int
int ypos; //declaring int
int spos; //declaring in spos
int delayT = 200; //declaring int delayT and setting = 200
int Servo1Angle; //declaring int servo1 angle
int Servo2Angle; //declaring int servo2 angle
Servo Xservo; //declaring servo name Xservo
Servo Yservo; //declaring servo name Yservo
void setup()
{
Serial.begin( 9600); //begin serial monitor
pinMode (X,INPUT); //set pinmode of A0 "X" to input data
pinMode ( Y, INPUT); //set pinmode of A1 "Y" to input data
pinMode (Push, INPUT); //set pinmode of pin 2 "PUSH" to input
digitalWrite (Push, HIGH); //put 5V on pushbutton
pinMode (Servo1, OUTPUT); //set pin 9 "servo1" to be an output
pinMode (Servo2, OUTPUT); //set pin 10 "servo2" to be an output
Xservo.attach (Servo1); //identy the output on analog pin 9 "servo1" as a servo
Yservo.attach (Servo2); //identify the output on analog pin 10 "servo2" as a servo
}
void loop()
{
xpos = analogRead (X); //update the value of int xpos to the read value from pin AO "X"
ypos = analogRead (Y); //update the value of in ypos to the read value from pin A1 "Y"
spos = digitalRead (Push); //update spos to read value from button pin 2
Servo1Angle = (analogRead (X)*180.0/1023.0); //update servo1angle with joystick input
Servo2Angle= (analogRead (Y)*180.0/1023.0); //update servo2angle with joystick input
Xservo.write (Servo1Angle); //write servo1andgle to Xservo
Yservo.write (Servo2Angle); //write servo2andgle to Yservo
delay (delayT); //delay loop by delayT
Serial.print ("X Position is ");Serial.print (xpos);
Serial.print (". Y Position is ");Serial.print (ypos);Serial.print (" Push is ");
Serial.println (spos);
}