#include <Servo.h>    //Include library to work with Servo motor

//Create Servo object, used to control a Servo (access functions, etc)
Servo myServo;        //12 Servo objects can be created on most boards

//Define a variable to store the values of joystick in horizontal direction
const int analogPin = A0;   //To read value in x-direction from joystick

//Define variable to store the Servo position, to rotate Servo in loop()
int value = 0;        //Will be converted from analog input to angle output
                      //(see the map() function used in main loop() below)

//setup code, to run once:
void setup() {//setup
  pinMode(analogPin, INPUT);       //Set SW_pin for input mode
  Serial.begin(9600);           //Open serial port at 9600 baud
  
  //Attach the Servo on pin 9 to the Servo object
  myServo.attach(9);
}//setup

//main code, to run repeatedly:
void loop() {//loop
  //Read in 10-bit analog value (0 to 1023) from joystick
  value = analogRead(analogPin);  //value variable will convert to degrees

  //Use map() to convert values to degrees (0 to 180) for Servo motor
  value = map(value, 0, 1023, 0, 180);

  //Use the converted value to move the Servo
  myServo.write(value);   //Move to a position specified by value (0 to 180)
  delay(15);              //Then wait 15ms
}//loop