Ok guys, I found a problem
Thanks to everyone for helping
The code now looks like this :
#include <Servo.h>
// constants won't change. They're used here to
// set pin numbers:
Servo myservo;
const int buttonPin1 = 2;
const int buttonPin2 = 3;
const int ledPin = 13;
// variables will change:
int buttonState1 = 0;
int buttonState2 = 0;
int pos = 0;
void setup() {
myservo.attach(9);
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
myservo.write(pos);
}
void loop(){
// read the state of the pushbutton value:
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
// turn LED on:
pos=pos+5;
myservo.write(pos);
digitalWrite(ledPin, HIGH);
delay(500);
}
if (buttonState2 == HIGH) {
// turn LED on:
pos=pos-5;
myservo.write(pos);
digitalWrite(ledPin, LOW);
delay(500);
}
}