#include <Button.h>
#include <Servo.h>
int sev1=9;
boolean openTheDoor=false;
boolean closeTheDoor=false;
Button btn=Button(6,PULLDOWN);
Servo sev2;
void setup(){
sev2.attach(10);
sev2.write(0);
}
void loop(){
if (openTheDoor){
openTheDoor=false;
}
if(closeTheDoor){
closeTheDoor=false;
}
if(btn.uniquePress()){
//open door
moveDoor1(1250);
//move bird
for(int i=0;i<120;i++){
sev2.write(i);
delay(10);
}
delay(2000);
for(int i=120;i>0;i--){
sev2.write(i);
delay(10);
}
//close door
moveDoor2(4000);
}
}
void moveDoor1( int d){
//this turns about 4 times
for(int i = 0; i <1900; i++){
digitalWrite(sev1,HIGH);
delayMicroseconds(d);
digitalWrite(sev1,LOW);
delayMicroseconds(d);
}
}
void moveDoor2( int d){
//this turns about 4 times
for(int i = 0; i<630; i++){
digitalWrite(sev1,HIGH);
delayMicroseconds(d);
digitalWrite(sev1,LOW);
delayMicroseconds(d);
}
}