|
i的值为1,2,3.分别为三次双舵机动作.
#include <Servo.h>
Servo myservo1;
Servo myservo2;
int k= 0;
int i= 0;
void abc(){
if(k==0){
k=1;
i++;
if(i>3)i=1;
}
}
void setup() {
Serial.begin(9600);
attachInterrupt(0, abc, FALLING );
myservo1.attach(9);
myservo2.attach(6);
pinMode(2,INPUT_PULLUP);
myservo1.write(0);
myservo2.write(0);
}
void loop() {
if((digitalRead(2)==LOW)&&(i==1)) {
myservo2.write(60);
myservo1.write(180);
delay(1000);
myservo1.write(0);
myservo2.write(0);
delay(1000);
}
if((digitalRead(2)==LOW)&&(i==2)) {
myservo2.write(60);
myservo1.write(90);
delay(1000);
myservo1.write(0);
delay(1000);
myservo1.write(180);
delay(1000);
myservo1.write(0);
myservo2.write(0);
}
if((digitalRead(2)==LOW)&&(i==3)) {
myservo2.write(60);
myservo1.write(70);
delay(1000);
myservo1.write(0);
delay(1000);
myservo1.write(120);
delay(1000);
myservo1.write(50);
delay(1000);
myservo1.write(180);
delay(1000);
myservo1.write(0);
myservo2.write(0);
}
k=0;
}
|
|