servo controled by 2 buttons in real time

Imgur

#include <Servo.h>

Servo myservo;
int leftPin = 8;
int rightPin = 9;
int servoPin = 13;
int pos = 100;
int delayPeriod = 3;

void setup()
{
myservo.attach (13);
pinMode(leftPin, INPUT);
pinMode(rightPin, INPUT);
pinMode(servoPin, OUTPUT);
}

void loop()
{
if(digitalRead(leftPin) == HIGH)
{
// in steps of 1 degree
if( pos > 0)
–pos;
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(delayPeriod);
}
if(digitalRead(rightPin) == HIGH)
{
if( pos < 180)
++pos;
myservo.write(pos); // tell servo to go to position in variable ‘pos’
delay(delayPeriod);
}
}