/* By sliding the potentiometer, we can change the angle of servo motor
   https://github.com/ostad-ai/Arduino-Tutorial
*/
// We use the Servo library to control the angle of the servo motor
// the angle of servo goes from 0 to 180 degrees
// we send PWM signal from a PWM-pin of arduino
// the frequency of PWM is usually 50 Hz
// the on-time of PWM should go from 1ms to 2ms
// which corresponds to angle interval [0,180] 
// the angle of servo motor is changed by moving slide potentiometer 
#include <Servo.h>
Servo myservo;
const int servo_pin=11,potentiometer_pin=A0;
int pos=0;
void setup() {
  // put your setup code here, to run once:
  myservo.attach(servo_pin);
  myservo.write(pos);
}

void loop() {
  // put your main code here, to run repeatedly:
  int value=analogRead(potentiometer_pin);
  pos=map(value,0,1023,0,180);
  myservo.write(pos);
  delay(20);
}