#include <Servo.h>

Servo servo1;
Servo servoLeft;  // Changed the name to avoid confusion
int value1 = LOW;
int value2 = LOW;
int ls = 8;
int rs = 9;
int servoPin = 10;
int servolPin = 11;
int defangle = 90;
int defangle2 = 45;

void setup() {
  pinMode(ls, INPUT);
  pinMode(rs, INPUT);
  servo1.attach(servoPin);
  servoLeft.attach(servolPin);
  Serial.begin(9600);
}

void loop() {
  function1();
  function2();
}

void function1() {
  value1 = digitalRead(ls);
  if (value1 == HIGH) {
    servo1.write(180);
    delay(750);
    servo1.write(defangle);
    Serial.end();  // Consider moving this to setup() if you want to end serial communication
  }
  value2 = digitalRead(rs);
  if (value2 == HIGH) {
    servo1.write(0);
    delay(750);
    servo1.write(defangle);
    Serial.end();  // Consider moving this to setup() if you want to end serial communication
  }
}

void function2() {
  servoLeft.write(defangle2);
  delay(4000);
  servoLeft.write(135);
  delay(350);
}