Activate a solenoid via an H-bridge for a specific period

Sorry guys, it's been a long time since I've been on the forum. FYI this will be small program to activate a solenoid via an H-bridge for a specific number of milliseconds for a small spot welder using a momentary switch. this will part of the code that will prevent the solenoid from activating more than once in case the switch depressed longer than the pulse being sent to the solenoid. Thanks for any help.

int duration=0;
bool buttonState=false;
void setup() {
  
  // put your setup code here, to run once:
  //int durattion=0;
  //bool buttonState=false;
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  while(Serial.available());
  {
    duration=Serial.parseInt();
    
  } 
  Serial.println(duration);
  
}

Split from an unrelated topic

Do not hijack topics or you run the risk of being banned

"code that will prevent the solenoid from activating more than once in case the switch depressed longer than the pulse being sent to the solenoid. "

You might do a forum search for “button toggle” for situations where a second button action is not initiated before the button is released. “Click” type buttons are easier to debounce.