//  Servo w/ switch
// 
//  Setup: - Wire a switch between digital pin 5 and ground
//         - Connect a servo to +, gnd and digital pin 6 
// -----------------------------------------------------------

#include <Servo.h>
int sw;           // variable for state of switch
int servoPin = 6; // variable for servo pin number
Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards
 
void setup() { 
  myservo.attach(servoPin);  // attaches the servo on pin 9 to the servo object
  pinMode(5, INPUT_PULLUP);  // Sets digital pin 5 for input (getting button state)
} 
 
void loop() { 
   sw = digitalRead(5);
 if(sw == LOW){                    // If switch is closed (pin connected to ground)
    myservo.write(180);            // tell servo to go to position 180 
    delay(10);  
 } else {                                         
    myservo.write(10);              // tell servo to go to position 0
    delay(10); 
  } 
} 
