Pan/Tilt Camera

You put all the pot/servo code in a conditional IF statement such that when the button/trigger is pushed the if statement is entered and the servos are positioned. When the button is released the conditional if is not entered, so the servos stay in their last positions and the joystick can be released. To recenter the servos with the joystick in its neutral position, just push the button and the servos will go to the current stick neutral position. below is some simple button code.

//zoomkat servo button test 12-29-2011

#include <Servo.h>
int button1 = 4; //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;

void setup()
{
  pinMode(button1, INPUT);
  pinMode(button2, INPUT);
  servo1.attach(7);
  digitalWrite(4, HIGH); //enable pullups to make pin high
  digitalWrite(5, HIGH); //enable pullups to make pin high
}

void loop()
{
  press1 = digitalRead(button1);
  if (press1 == LOW)
  {
    servo1.write(170);
  }    
  
  press2 = digitalRead(button2);
  if (press2 == LOW)
  {
    servo1.write(10);
  }
}