int button = 2;
int button1 = 3;
int led = 4;
int led1 = 6;
#include<Servo.h> //include the servo library
Servo servo; //create a servo object
int pos = 0; //initial position of the servo
void setup() {
// put your setup code here, to run once:
servo.attach(9); //pin used by the servo
pinMode(button, INPUT_PULLUP); //define first button as input pullup
pinMode(button1, INPUT_PULLUP); //define second button as input pullup
pinMode(led, OUTPUT); //define first led
pinMode(led1, OUTPUT); //define second led
}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(button) == LOW) { //if Value read of the button ==LOW:
pos++; //increases the value of the "pos" variable each time the push button of the left is pressed
delay(5); //5 milliseconds of delay
servo.write(pos); //servo goes to variable pos
digitalWrite(led, HIGH);
digitalWrite(led1, LOW);
}
if (digitalRead(button1) == LOW) { //if Value read of the button ==LOW:
pos--; //decreases the value of the "pos" variable each time the push button of the right is pressed
delay(5); //5 milliseconds of delay
servo.write(pos); //servo goes to variable pos
digitalWrite(led1, HIGH);
digitalWrite(led, LOW);
}
}