Servo with a Bumper Switch

Hi forum! So, I’m making a robotic claw and right now I’m just looking for advice on both how to wire and code. I’ll attach the code, right now it’s just a circuit connecting the switch, arduino microcontroller and the servo. It doesn’t need a breadboard though.What the code does right now is make the claw open and close, and when we trigger the bumper switch it stops moving. What we want it to do is open on its own with the servo, but close with the triggering of the bumper switch and open again when we let it go. Can someone suggest some code?

//include the servo library in your sketch
#include <Servo.h>

//Create a servo object called myServo
Servo myServo;
//create a global boolean variable to toggle
//when button is pressed, set it to true.
int buttonState = 0;

void setup() 
{
  //pinModes for H-Bridge control pins
  myServo.attach(9);
  //set pin 6 to INPUT_PULLUP, no need for a pullup resistor
  pinMode(6,INPUT_PULLUP);
}

void loop() 
{
 
 
 //if buttonState is 0 (less than 1) toggle the state variable to 
 //the opposite of the current state (!state)
 if(digitalRead(6)==0)
 {
     buttonState++;
    delay(500);
 }
 
 
 //if state is false move myServo to 145, else 20.
 if(buttonState==1)
 {
  myServo.write(160);
 }
 else if(buttonState==2)
 {
  myServo.write(180);
 }
 else if(buttonState==3)
 {
 myServo.write(200);
 }
 else if(buttonState >= 4)
 {
 myServo.write(40); 
 buttonState=0;
 }
}

I'm not getting my head round your requirements, sorry.

I think you need to clarify what happens next a-h under each possible set of circumstances. (Some of a-h may be "do nothing"; some combinations below may be impossible)

claw is closed, switch is open but not changing, servo does a
claw is closed, switch is closed but not changing, servo does b
claw is closed, switch goes from open to closed, servo does c
claw is closed, switch goes from closed to open, servo does d

claw is open, switch is open but not changing, servo does e
claw is open, switch is closed but not changing, servo does f
claw is open, switch goes from open to closed, servo does g
claw is open, switch goes from closed to open, servo does h