Some test code from a little while back that used buttons, but that could be substituted with pot values like <500 and >540 to control the direction of the servo movement.
//zoomkat servo button sweep test 12-23-2013
// Powering a servo from the arduino usually *DOES NOT WORK*.
#include <Servo.h>
int button1 = 6; //button pin, connect to ground to move servo
int press1 = 0;
int button2 = 5; //button pin, connect to ground to move servo
int press2 = 0;
Servo servo1;
int pos = 90; // variable to store and set the servo position
void setup()
{
Serial.begin(9600);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
servo1.attach(7);
servo1.write(pos); //starting position
digitalWrite(6, HIGH); //enable pullups to make pin high
digitalWrite(5, HIGH); //enable pullups to make pin high
Serial.println("servo button sweep test 12-23-2013");
}
void loop()
{
press1 = digitalRead(button1);
if (press1 == LOW)
{
pos=(pos+1);
if(pos>180) pos=180; //limit upper value
Serial.println(pos); //for serial monitor debug
servo1.write(pos); // tell servo to go to position in variable 'pos'
delay(150); // waits 150ms to slow servo movement
}
press2 = digitalRead(button2);
if (press2 == LOW)
{
pos=(pos-1);
if(pos<0) pos=0; //limit lower value
Serial.println(pos); //for serial monitor debug
servo1.write(pos); // tell servo to go to position in variable 'pos'
delay(150); // waits 150ms to slow servo movement
}
}