#include <Servo.h> 

Servo doorServo;
Servo fingerServo;

int swPin = 2;               //switch on pin 2

int pos = 0;
int selectedMove = 0;             //move selector

void setup()
{
  pinMode(swPin, INPUT);
  doorServo.attach(9);           //set door servo on Pin 9 pwm
  fingerServo.attach(10);          //set finger servo on Pin 10 pwm
  doorServo.write(160);           //set door to hiding position 
  fingerServo.write(180);            //set finger to hiding position
}


void loop(){

  //if the switch is on, move door and finger to switch it off
  if(digitalRead(swPin) == HIGH)
  {
    
    if (selectedMove > 11) { 
    selectedMove = 0; 
    } //when all moves are played, repeat the moves from beginning 
    
    if (selectedMove == 0) { 
    simpleClose(); 
    }
    else if (selectedMove == 1) { 
    simpleClose2(); 
    }   
    else if (selectedMove == 2) { 
    serious(); 
    }
    else if (selectedMove == 3) { 
    crazydoor(); 
    }
    else if (selectedMove == 4) { 
    slow(); 
    }
    else if (selectedMove == 5) { 
    serious(); 
    }
    else if (selectedMove == 6) { 
    trollClose(); 
    }
    else if (selectedMove == 7) { 
    simpleClose2(); 
    }
    else if (selectedMove == 8) { 
    matrix(); 
    }
    else if (selectedMove == 9) { 
    sneak(); 
    }
    else if (selectedMove == 10) { 
    PAJ1(); 
    }
    else if (selectedMove == 11) { 
    PAJ2(); 
    }
     
   selectedMove += 1;         //swith to next move 
   
  }
}



// Moves

// basic move 
void simpleClose() 
  {   
 
  //Moving door
    for(pos = 160; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
   
  //Moving hand
    for(pos = 180; pos > 8; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
      
  //hiding door
    for(pos = 100; pos<=160; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
  } 
     

// open wait, then move finger and wait, then switch of and hide  
void simpleClose2()
  {
 
  //Moving door
    for(pos = 160; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(800); 
    
  //Moving hand
    for(pos = 180; pos > 40; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }

       delay(1000); 

  //Moving hand
    for(pos = 40; pos > 8; pos -= 2)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }    
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=5)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
      
  //hiding door
    for(pos = 100; pos<=160; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                    
    } 
  }

  
//open door close many times,wait,reopen,switch off and hide.
void crazydoor()
  {
    
  //Moving door
    for(pos = 160; pos > 130; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 130; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 130; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 130; pos<=160; pos+=15)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

       delay(700);

  //Moving door
    for(pos = 160; pos > 130; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(700);

  //hiding door
    for(pos = 130; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 100; pos -= 8)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
   
  //Moving hand
    for(pos = 180; pos > 8; pos -= 3)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=3)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
      
  //hiding door
    for(pos = 100; pos<=160; pos+=15)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    }    
  }   


//open door,finger slowly forward back, then quickly close door
void slow()
  {
 
  //Moving door
    for(pos = 160; pos > 100; pos -= 2)   
    {                                   
    doorServo.write(pos);              
    delay(30);                       
    }
   
  //Moving hand
    for(pos = 180; pos > 8; pos -= 2)  
    {                                   
    fingerServo.write(pos);               
    delay(30);                       
    }  
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=2)      
    {                                
    fingerServo.write(pos);               
    delay(30);                        
    } 
      
  //hiding door
    for(pos = 100; pos<=130; pos+=2)     
    {                                
    doorServo.write(pos);              
    delay(30);                      
    }

       delay(500);

  //hiding door
    for(pos = 130; pos<=160; pos+=4)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    }     
  } 


//serious
void serious()
  {
 
  //Moving door
    for(pos = 160; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
     
  //Moving hand
    for(pos = 180; pos > 25; pos -= 1)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }
  
       delay(800);
        
  //hiding door
    for(pos = 100; pos<=130; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15); 
    }
    
  //moving door
    for(pos = 130; pos > 100; pos-=3)     
    {                                
    doorServo.write(pos);              
    delay(15); 
    } 

  //hiding door
    for(pos = 100; pos<=130; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15); 
    }   
   
  //moving door
    for(pos = 130; pos > 100; pos-=3)     
    {                                
    doorServo.write(pos);              
    delay(15); 
    } 
    
       delay(1000);
      
  //Moving hand
    for(pos = 25; pos > 8; pos -= 3)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    } 
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=3)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
    
  //hiding door  
    for(pos = 100; pos<=160; pos += 1)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  } 


void trollClose()
  {

  //Moving door
    for(pos = 160; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
   
  //Moving hand
    for(pos = 180; pos > 16; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }

  //hiding door
    for(pos = 100; pos<=140; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    }   

       delay(2000);
    
  //Moving door
    for(pos = 140; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

  //hiding door
    for(pos = 100; pos<=120; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);
    }
    
  //Moving door
    for(pos = 120; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(500);

  //Moving hand
    for(pos = 16; pos > 8; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }

  //hiding hand
    for(pos = 8; pos<=180; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
      
  //hiding door
    for(pos = 100; pos<=160; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
  }
   

void matrix()
  {

 //Moving door
    for(pos = 160; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
   
  //Moving hand
    for(pos = 180; pos > 40; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }
    
  //Moving hand
    for(pos = 40; pos > 8; pos -= 1)  
    {                                   
    fingerServo.write(pos);               
    delay(30);                       
    }  

       delay(300);
    
 //hiding hand
    for(pos = 8; pos<=180; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(10);                        
    } 
      
 //hiding door
    for(pos = 100; pos<=160; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
  }


void sneak() 
  { 
   
   //Moving door
    for(pos = 160; pos > 130; pos -= 1)   
    {                                   
    doorServo.write(pos);              
    delay(30);                       
    }

       delay(2000);
    
  //Moving hand
    for(pos = 180; pos > 130; pos -= 1)  
    {                                   
    fingerServo.write(pos);               
    delay(30);                       
    }  
        
       delay(500);

  //Moving door
    for(pos = 130; pos > 100; pos -= 4)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(100);

  //Moving hand
    for(pos = 130; pos > 60; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  

       delay(500);

  //hiding hand
    for(pos = 60; pos<=90; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    }

       delay(100);

  //Moving hand
    for(pos = 90; pos > 50; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }

       delay(100);

  //hiding hand
    for(pos = 50; pos<=80; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    }

       delay(100);
       
  //Moving hand
    for(pos = 80; pos > 8; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    }    

  //hiding door
    for(pos = 100; pos<=160; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
  } 
   

//Super pissed off.
void PAJ1()
  {
    
  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 110; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 110; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 
       delay(3000);

  //Moving door
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
       delay(1000);

  //hiding door
    for(pos = 100; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

       delay(1000);

  //Moving door
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
       delay(1000);

  //hiding door
    for(pos = 100; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

       delay(1000);

  //Moving door
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }


  //hiding door
    for(pos = 100; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

  //Moving door
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(2500);
   
  //Moving hand
    for(pos = 180; pos > 25; pos -= 5)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                      
    }  

       delay(1000);    

  //hiding hand
    for(pos = 25; pos<=100; pos+=5)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
  
  //Moving hand
    for(pos = 100; pos > 25; pos -= 5)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  

       delay(1000);    


  //hiding hand
    for(pos = 25; pos<=100; pos+=5)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
  
  //Moving hand
    for(pos = 100; pos > 25; pos -= 5)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  


  //hiding hand
    for(pos = 25; pos<=100; pos+=5)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
  
  //Moving hand
    for(pos = 100; pos > 25; pos -= 5)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  

  //hiding hand
    for(pos = 25; pos<=100; pos+=5)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
  
  //Moving hand
    for(pos = 100; pos > 25; pos -= 5)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  

       delay(3000);    

  //Moving hand
    for(pos = 25; pos > 8; pos -= 1)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  

       delay(2500);    

  //hiding hand
    for(pos = 8; pos<=180; pos+=2)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 

       delay(1000);    

  //hiding door
    for(pos = 100; pos<=130; pos+=1)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    }    

       delay(800);    

  //hiding door
    for(pos = 130; pos<=160; pos+=1)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    }

       delay(1000);  

  //Moving door
    for(pos = 160; pos > 100; pos -= 10)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(1000);    

  //hiding door
    for(pos = 100; pos<=160; pos+=10)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    }
  }   

      //Super crazy.
void PAJ2()
  {
    
  //Moving door 1
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 

  //Moving door 2
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 3
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 4
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 5
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 6
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 7
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 8
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 

      delay(1000);


  //Moving door 1
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 

     
  //Moving door 2
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=180; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    
  //Moving door 3
    for(pos = 180; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
  
  //hiding door
    for(pos = 100; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
    

      delay(3000);      

 
  //Moving door
    for(pos = 160; pos > 100; pos -= 3)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }
   
  //Moving hand
    for(pos = 180; pos > 8; pos -= 4)  
    {                                   
    fingerServo.write(pos);               
    delay(15);                       
    }  
    
  //hiding hand
    for(pos = 8; pos<=180; pos+=4)      
    {                                
    fingerServo.write(pos);               
    delay(15);                        
    } 
      
  //hiding door
    for(pos = 100; pos<=160; pos+=3)     
    {                                
    doorServo.write(pos);              
    delay(15);                      
    } 

       delay(1000);      

  //Moving door 
    for(pos = 160; pos > 100; pos -= 5)   
    {                                   
    doorServo.write(pos);              
    delay(15);                       
    }

       delay(1000);      
  
  //hiding door
    for(pos = 100; pos<=160; pos+=5)     
    {                                
    doorServo.write(pos);          
    delay(15);                      
    } 
  } 
      
