#include <Servo.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <ezButton.h>

ezButton plusbtn(4);  

ezButton nextbtn(2); 

ezButton minusbtn(5);  

ezButton setbtn(3);
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 32 // OLED display height, in pixels

#define OLED_RESET     -1 // Reset pin # (or -1 if sharing Arduino reset pin)
#define SCREEN_ADDRESS 0x3C ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);


Servo myservo;

#define servoPin 11
#define motorPin 10
#define buzzerPin 9

// #define plusbtn 4
// #define nextbtn 2
// #define setbtn 3
// #define minusbtn 5


int set = 0;  int minus = 0;
int plus = 0;  int next = 0;

int resetVal = 0;  int resetFile = 0;
int folder = 0; int file = 0;
int fold_set = 0; int file_set = 0;
int lastFolder = 0;
int disp_set = 0;

unsigned long start_time;



void setup()
{
  Serial.begin(9600);
  // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for (;;); // Don't proceed, loop forever
  }

  // Show initial display buffer contents on the screen --
  // the library initializes this with an Adafruit splash screen.
  display.display();
  delay(2000); // Pause for 2 seconds

  // Clear the buffer
  display.clearDisplay();
  delay(100);
  display.clearDisplay();

   setbtn.setDebounceTime(100);
   nextbtn.setDebounceTime(100);
   plusbtn.setDebounceTime(100);
   minusbtn.setDebounceTime(100);
   pinMode(2, INPUT_PULLUP);
   pinMode(3, INPUT_PULLUP);
   pinMode(4, INPUT_PULLUP);
   pinMode(5, INPUT_PULLUP);
  pinMode(motorPin, OUTPUT);
  pinMode(servoPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  myservo.attach(servoPin);

  // attachInterrupt(digitalPinToInterrupt(setbtn), SET, FALLING);
  // attachInterrupt(digitalPinToInterrupt(nextbtn), NEXT, FALLING);
  //start();
  disp_set = 0;
  resetVal = 0;
  resetFile = 0;
  folder = 0;
  file = 0;
  fold_set = 0;
  file_set = 0;
  lastFolder = 0;
tone(buzzerPin, 500); // (pin no of buzzer, frequency)
  delay(1000);
  noTone(buzzerPin); // releasing buzzer from last frquency must step to do before generating another fequency
  delay(1000);
  tone(buzzerPin, 1300); // (pin no of buzzer, frequency)
  delay(1000);
  noTone(buzzerPin);
  delay(1000);
}

void loop()


{
  setbtn.loop();
nextbtn.loop();
plusbtn.loop();
minusbtn.loop();

 // plus = digitalRead(plusbtn);
  //minus = digitalRead(minusbtn);

  if(plusbtn.isPressed())
  {
    if (fold_set == 0)
    {
      folder++;
      lastFolder = folder;
    }
    if (fold_set == 1 && file_set != 1)
    {
      file++;
    }
    Serial.println("Plus button Pressed");
    
  }
if(minusbtn.isPressed())
  {
    if (folder > 0 && fold_set == 0)
      folder--;
    if (file > 0 && fold_set == 1)
      file--;
    Serial.println("Minus button Pressed");
    
  }
      if(setbtn.isPressed())
  {
SET();
  }
   if(nextbtn.isPressed())
  {
NEXT();
  }

  if (disp_set == 0 ) {
    // This is the function for folder selection
    display.clearDisplay(); // to clear the display before printing anything on screen if we don't do that then it will overwrite on the previous printed data.
    display.setTextSize(1); // font size of characters. you can put 1,2,3.. for different sizes
    display.setTextColor(SSD1306_WHITE); // color of font.
    display.setCursor(0, 0); // to set the cursor for printing data display.setCursor(x,y);
    display.println("Select Folder "); // data in " " inverted commas will be printed as it is on the screen where we set the cursor. display.println() function prints that line and go to next line
   display.println("Folder : " + String(folder)); // It will display Folder : as it is because it is in inverted commas and it will display the value of the folder variable next to it.
    display.display(); // this function is used to display the whole data that we want to display
    delay(10); // small delay
  }
  if (disp_set == 1) {
    // This function is for file selection. i have used same functions as i did for folder selection function.
    display.clearDisplay();
    display.setTextSize(1);
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(20, 0);
    display.println("Select File ");
    display.println("File : " + String(file));
    display.display();
    delay(10);
  }
  if (disp_set == 2  ) {
    // This function is to display which folder and file is selected.
    display.clearDisplay();

    display.setTextSize(1);// i have used different font size here from file and folder selection function
    display.setTextColor(SSD1306_WHITE);
    display.setCursor(0, 0); // different cursor position
    if (folder == 1 ) { // change the folder == ? to specific folder you want
      display.println("Folder: " + String(folder));
      display.println("File: " + String(file));
      display.println("Alpha");// name for folder 1
    }
    else if (folder == 2 ) {
      display.println("Folder: " + String(folder));
      display.println("File: " + String(file));
      display.println("Bravo");// name for folder 1
    }
    else if (folder == 3 ) {
      display.println("Folder: " + String(folder));
      display.println("File: " + String(file));
      display.println("Charlie");// name for folder 1
    }
    else {
      display.println("Folder: " + String(folder));
      display.println("File: " + String(file));

    }
    display.display();
    delay(10);
  }



  if (resetVal >= 2)
  {
    resetVal = 0;
    folder = 0;
    file = 0;
    file_set = 0;
    fold_set = 0;
    disp_set = 0;
    stop();
  }


  if (resetFile >= 2)
  {
    resetFile = 0;
    folder = lastFolder;
    fold_set = 1;
    file = 0;
    file_set = 0;
    disp_set = 1;
    stop();
  }

  if (folder == 0 || file == 00)
  {
    stop();
  }
  if (folder == 1 && file == 1 && file_set == 1)
  {
    start_file1();
    fold1_file1();
  }

  if (folder == 1 && file == 2 && file_set == 1)
  {
    start_file2();
    fold1_file2();
  }

  if (folder == 1 && file == 3 && file_set == 1)
  {
    start_file3();
    fold1_file3();
  }

  if (folder == 1 && file == 4 && file_set == 1)
  {
    start_file4();
    fold1_file4();
  }

  if (folder == 1 && file == 5 && file_set == 1)
  {
    start_file5();
    fold1_file5();
  }

  if (folder == 1 && file == 6 && file_set == 1)
  {
    start_file6();
    fold1_file6();
  }

  if (folder == 1 && file == 7 && file_set == 1)
  {
    start_file7();
    fold1_file7();
  }

  if (folder == 1 && file == 8 && file_set == 1)
  {
    start_file8();
    fold1_file8();
  }

  if (folder == 1 && file == 9 && file_set == 1)
  {
    start_file9();
    fold1_file9();
  }


  if (folder == 1 && file == 10 && file_set == 1)
  {
    start_file10();
    fold1_file10();
  }

  if (folder == 2 && file == 1 && file_set == 1)
  {
    start_file1();
    fold2_file1();
  }

  if (folder == 2 && file == 2 && file_set == 1)
  {
    start_file2();
    fold2_file2();
  }

  if (folder == 2 && file == 3 && file_set == 1)
  {
    start_file3();
    fold2_file3();
  }
}

void NEXT()
{
  if (fold_set == 1 && file_set == 1)
    resetFile++;
  if (fold_set == 0) {
    fold_set = 1;
    disp_set = 1;
  }
  //delay(500);

  Serial.println("NEXT");
}

void SET()
{
  if (file_set == 1)
    resetVal++;
  if (file_set == 0) {
    file_set = 1;
    disp_set = 2;
  }
  Serial.println("SET");
 // delay(500);
}

void stop()
{
  digitalWrite(motorPin, LOW);
  myservo.write(90);
}

void start()
{
  start_time = millis();
  while ((millis() - start_time) < 4000)
    myservo.write(90);
  //shave
  digitalWrite(motorPin, HIGH);
  delay(200);
  digitalWrite(motorPin, LOW);
  delay(600);
  //and
  digitalWrite(motorPin, HIGH);
  delay(200);
  digitalWrite(motorPin, LOW);
  delay(200);
  //a
  digitalWrite(motorPin, HIGH);
  delay(200);
  digitalWrite(motorPin, LOW);
  delay(200);
  //hair
  digitalWrite(motorPin, HIGH);
  delay(400);
  digitalWrite(motorPin, LOW);
  delay(200);
  //cut
  digitalWrite(motorPin, HIGH);
  delay(200);
  digitalWrite(motorPin, LOW);
  delay(800);
  //two
  digitalWrite(motorPin, HIGH);
  delay(200);
  digitalWrite(motorPin, LOW);
  delay(200);
  //bits
  digitalWrite(motorPin, HIGH);
  delay(200);
  digitalWrite(motorPin, LOW);
  delay(200);
}


void start_file1()
{
  start_time = millis();
  while ((millis () - start_time) < 200){
    
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
SET();
   if(nextbtn.isPressed())
NEXT();
    digitalWrite(motorPin, HIGH);
    }

  start_time = millis();
  while ((millis() - start_time) < 200){ 
  setbtn.loop();
nextbtn.loop();   
    if(setbtn.isPressed())
SET();
   if(nextbtn.isPressed())
NEXT();
    digitalWrite(motorPin, LOW);
    }
}


void start_file2()
{
  for(int i=0; i<2; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
}


void start_file3()
{
   for(int i=0; i<3; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
 }


void start_file4()
{
    for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
}


void start_file5()
{
     for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
 }


void start_file6()
{
   for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
 }


void start_file7()
{
      for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
  }


void start_file8()
{
    for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
 }


void start_file9()
{
    for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
}


void start_file10()
{
      for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
 }


void start_file11()
{
      for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
 }

void start_file12()
{
    for(int i=0; i<file; i++){
  start_time = millis();
  while ((millis() - start_time) < 200) {
     tone(buzzerPin, 500); // (buzzerPin, frequency)   
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  start_time = millis(); 
    while ((millis() - start_time) < 200){
  noTone(buzzerPin);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
  
  }
  Serial.println("value :" + String(i)); 
}
}


void fold1_file1()
{
  if (file == 1)
  {
    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 200)
    {
      digitalWrite(motorPin, LOW);
    }
  }

  else
    return;
}


void fold1_file2()
{
  if (file == 2)
  {
    start_time = millis();
    while ((millis() - start_time) < 1600){
      myservo.write(0);
  setbtn.loop();
nextbtn.loop();
if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
    }
    start_time = millis();
    while ((millis() - start_time) < 200){
      myservo.write(90);
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
    }

    start_time = millis();
    while ((millis() - start_time) < 3000){
      digitalWrite(motorPin, HIGH);
      tone(buzzerPin, 1000); //(buzzer pin, frquency)

  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
      }

    start_time = millis();
    while ((millis() - start_time) < 200){
      digitalWrite(motorPin, LOW);
      noTone(buzzerPin);
    
  setbtn.loop();
nextbtn.loop();
    if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
      }

    start_time = millis();
    while ((millis() - start_time) < 1600)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
     
  setbtn.loop();
nextbtn.loop();
      if(setbtn.isPressed())
      SET();
   if(nextbtn.isPressed())
    NEXT();
    }
  
    
    }
  else
    return;
}


void fold1_file3()
{
  if (file == 3)
  {
    start_time = millis();
    while ((millis() - start_time) < 2500)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 2500)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}


void fold1_file4()
{
  if (file == 4)
  {
    start_time = millis();
    while ((millis() - start_time) < 3400)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 3400)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}

void fold1_file5()
{
  if (file == 5)
  {
    start_time = millis();
    while ((millis() - start_time) < 4300)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 4300)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}


void fold1_file6()
{
  if (file == 6)
  {
    start_time = millis();
    while ((millis() - start_time) < 5200)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 5200)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}


void fold1_file7()
{
  if (file == 7)
  {
    start_time = millis();
    while ((millis() - start_time) < 6100)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 6100)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}


void fold1_file8()
{
  if (file == 8)
  {
    start_time = millis();
    while ((millis() - start_time) < 7000)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 7000)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}



void fold1_file9()
{
  if (file == 9)
  {
    start_time = millis();
    while ((millis() - start_time) < 7900)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 7900)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}


void fold1_file10()
{
  if (file == 10)
  {
    start_time = millis();
    while ((millis() - start_time) < 8800)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(90);

    start_time = millis();
    while ((millis() - start_time) < 3000)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 8800)
    {
      digitalWrite(motorPin, LOW);
      myservo.write(180);
    }
  }

  else
    return;
}


void fold2_file1()
{
  if (file == 1)
  {
    start_time = millis();
    while ((millis() - start_time) < 200)
      myservo.write(180);

    start_time = millis();
    while ((millis() - start_time) < 200)
    {
      myservo.write(90);
    }
  }

  else
    return;
}


void fold2_file2()
{
  if (file == 2)
  {
    start_time = millis();
    while ((millis() - start_time) < 600)
      myservo.write(180);

    start_time = millis();
    while ((millis() - start_time) < 200)
    {
      myservo.write(90);
    }
  }

  else
    return;
}


void fold2_file3()
{
  if (file == 3)
  {
    start_time = millis();
    while ((millis() - start_time) < 1300)
      myservo.write(0);

    start_time = millis();
    while ((millis() - start_time) < 1250)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 1200)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 730)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 560)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 900)
      digitalWrite(motorPin, HIGH);

    start_time = millis();
    while ((millis() - start_time) < 1500)
      digitalWrite(motorPin, LOW);

    start_time = millis();
    while ((millis() - start_time) < 1300)
      myservo.write(180);
  }

  else
    return;
}