#include <Servo.h> //accesses the Arduino Servo Library
Servo myservo; // creates servo object to control a servo
int val; // variable to read the value from the analog pin
void setup() {
// put your setup code here, to run once:
myservo.attach(9); // ensures output to servo on pin 9
}
void loop() {
// put your main code here, to run repeatedly:
val = analogRead(1); // reads the value of the potentiometer from A1 (value between 0 and 1023)
val = map(val, 0, 1023, 0, 320); // converts reading from potentiometer to an output value in degrees of rotation that the servo can understand
myservo.write(val); // sets the servo position according to the input from the potentiometer
delay(15); // waits 15ms for the servo to get to set position
}