Struggling with bouncing servos

In this project I am attempting to do a few things. When the upper switch is on HIGH the upper button triggers both servos open upon press and then closed upon another press. When the upper switch is on LOW each button should trigger only one servo (upper and lower buttons are tied to servos respectively) and a similar press to open-press to close process should occur. For the most part this is successful, however I seem to be having issues with the button states bouncing. I have tried to include a debounce delay however there seems to be no delay value in between bouncing, and taking way too long to trigger. Additionally, there seems to be cases where the button input is just entirely missed?
Thanks in advance!

#include <Servo.h>
Servo servo1;
Servo servo2;
int buttonState1 = 0;      // the current state of the button
int lastbuttonState1 = 0;  // the previous state of the button
int buttonState2 = 0;
int lastbuttonState2 =0;
int switch_state;
const int switch_pin = 4; // switch outlet
const int buttonPin = 2; // input number connected to sensor №1
const int buttonPin2 = 3; // input number connected to sensor №2
const int servo1_pin = 8; // the output number for the servo drive №1
const int servo2_pin = 9; // the output number for the servo drive №2
const int servo_angle = 94; // the angle at which the servo will turn
void setup()
{
  pinMode(buttonPin, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(switch_pin, INPUT);
  Serial.begin(115200);
  servo1.attach(servo1_pin);
  servo2.attach(servo2_pin);
}

void loop()
{
  switch_state = digitalRead(switch_pin);
if (switch_state == HIGH)
  {
    Serial.print("BOTH EYES MODE ");
    // read the state of the button
    buttonState1 = digitalRead(buttonPin);
    // check if the button was just pressed
    if (buttonState1 != lastbuttonState1) {
    // debounce delay
    delay(50);
    if (lastbuttonState1 == LOW && buttonState1 == HIGH) {
      Serial.print("Closing");
        servo1.write(-servo_angle);
        servo2.write(-servo_angle);
        delay(140);
    }
    else {
      Serial.print("Opening");
        servo1.write(servo_angle);
        servo2.write(servo_angle);
        delay(140);
    }
    
       // save the current button state for comparison in the next loop
  lastbuttonState1 = buttonState1;
    }
  }
else {
  Serial.print("SINGLE EYE MODE");
buttonState1 = digitalRead(buttonPin);
buttonState2 = digitalRead(buttonPin2);
    // check if the button was just pressed
    if (buttonState1 != lastbuttonState1) {
    // debounce delay
    delay(50);
    if (lastbuttonState1 == LOW && buttonState1 == HIGH) {
      Serial.print("Closing 1");
        servo1.write(-servo_angle);
        delay(140);
    }
    else {
      Serial.print("Opening 1");
        servo1.write(servo_angle);
        delay(140);
    }
    
       // save the current button state for comparison in the next loop
  lastbuttonState1 = buttonState1;
  delay(20);
    }
    // check if the button was just pressed
    if (buttonState2 != lastbuttonState2) {
    // debounce delay
    delay(50);
    if (lastbuttonState2 == LOW && buttonState2 == HIGH) {
      Serial.print("Closing 2");
        servo2.write(-servo_angle);
        delay(140);
    }
    else {
      Serial.print("Opening 2");
        servo2.write(servo_angle);
        delay(140);
    }
    
       // save the current button state for comparison in the next loop
  lastbuttonState2 = buttonState2;
  delay(20);
}
}
}

Capture

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Yeah I was just fixing that

that fritzthing is hard to discern what's going on. Are you interrupting power with the switches to the servos?

Are you supplying servo power from the MCU?

Of course button pushes can be missed. When a delay() is in progress nothing is happening. Means button pressed are not detected. In reality your code spends more time in delay than running code.

Look at File|Examples|02.Digital|BlinkWithoutDelay to use millis() for timing instead of delay().

Servo stuff

Power externally.

All the slide switch is connected to is MCU power and pin D4. This is used to switch eye modes from dual eyes to single eyes by having D4 read HIGH or LOW. I agree the delays are perhaps unnecessary however even removing them / replacing them with milis() won’t change the primary issue I wouldn’t think?

Opted to switch for OneButton library setup to utilize its more streamlined debounce system.