int servo = 4;
int button = 2;
int angle;
int pwm;
int y=0;
void setup()
{
pinMode(servo, OUTPUT);
pinMode(button, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2),motor,FALLING);
Serial.begin(9600);
}
void loop()
{
if(y==1){
servoPulse(servo, angle*y+30);
delay(1000*y);
servoPulse(servo, (angle+60)*y+30);
delay(100*y);
}
else { servoPulse(servo,angle);}
delay(50);
if(digitalRead(button)==1){attachInterrupt(digitalPinToInterrupt(2),motor,FALLING);}
}
void motor()
{
if(y==1){y=0; angle=30;}
else {y=1;angle=70;}
detachInterrupt(digitalPinToInterrupt(2));
Serial.println(y);
}
void servoPulse (int servo, int angle)
{
pwm = (angle*11)+500;
digitalWrite(servo, HIGH);
delayMicroseconds(pwm);
digitalWrite(servo, LOW);
delay(50);
}