// add the servo library
#include <Servo.h>
// define servo
Servo servo1;
Servo servo2;
// define joystick pins
int joyX = 0;
int joyY = 1;
// variabl to read the value from the analog pins
int servoVal;
void setup()
{
Serial.begin(9600);
//attaches our servo on pins PWM 3-5
servo1.attach(3);
servo2.attach(5);
}
void loop()
{
//read the value of joystick (between 0-1023)
servoVal = analogRead(joyX);
servoVal = map(servoVal, 0, 1023, 0, 180); //servo value between 0-180
servo1.write(servoVal); //set the servo position according to the joystick value
Serial.println(String("servo1 = ") + servoVal);
servoVal = analogRead(joyY);
servoVal = map(servoVal, 0, 1023, 0, 180);
servo2.write(servoVal);
Serial.println(String("servo2 = ") + servoVal );
delay(15);
}