volatile int i=90;//initializing a integer for incrementing and decrementing duty ratio
bool x;
#include <Servo.h> // header file for controlling servo
Servo myservo;//defining the name usage as servo itself
void setup()
{
Serial.begin(9600);
myservo.attach(3);
//pinMode(3, OUTPUT); // sets the pin3 as output
pinMode(5, INPUT_PULLUP);// sets the pin0 as output
pinMode(6, INPUT_PULLUP);// sets the pin1 as output
}
void loop()
{
myservo.write(i);//set servo potion ‘i’ degrees
x=digitalRead(5);
if (x==LOW)
{
if (i<180)
{
i++;//if pin0 is pressed and degrees is less than 180
Serial.println(i);
delay(30);
}
}
x=digitalRead(6);
if (x==LOW)
{
if (i>0)
{
i--;// if pin1 is pressed and degrees is greater than 0
Serial.println(i);
delay(30);
}
}
delay(30);
}