volatile int i=0;//initializing a integer for incrementing and decrementing duty ratio.
void setup()
{
pinMode(3, OUTPUT); // sets the pin3 as output
pinMode(0, INPUT);// sets the pin0 as output
pinMode(1, INPUT);// sets the pin1 as output
}
void loop()
{
analogWrite(3, i); // analogWrite values from 0 to 255
if (digitalRead(0)==LOW)
{
if (i<255)
{
i++;//if pin0 is pressed and the duty ratio value is less than 255
delay(30);
}
}
if (digitalRead(1)==LOW)
{
if (i>0)
{
i--;// if pin1 is pressed and the duty ratio value is greater than 0
delay(30);
}
}
}