Switching Servo on 10 seconds after button press

I’m trying to to switch the servo to 65 degree position and buzzer and LED on when the button is pressed for more than 10 seconds.

This doesn’t seem to work:

#include<Servo.h>


const int ButtonPin = 13 ;
const int LedPin = 12;
const int BuzzPin= 11;
const int ServoPin = 10;
Servo MyServo;
int buttonState = 0;
int LedState =0 ;
int BuzzerState;
int ServoPos =0;


int ButtonPressMillis;

void setup()
{
  pinMode(LedPin,OUTPUT);
  pinMode(BuzzPin,OUTPUT);
  pinMode(ButtonPin,INPUT);
  MyServo.attach(ServoPin);
  MyServo.write(5);
}


void loop()
{buttonState=digitalRead(ButtonPin);
  if(buttonState == HIGH)
  {digitalWrite(LedState, HIGH);
  digitalWrite(BuzzerState,HIGH);
  ButtonPressMillis = millis();
  if(ButtonPressMillis> 10000)
  {
   MyServo.write(65);
   delay(300);
  }
  
  }
  {
  digitalWrite(LedState, LOW);
  digitalWrite(BuzzerState,LOW);
  MyServo.write(5);
  ButtonPressMillis = 0;
  }

  
}
int ButtonPressMillis;

The millis() function does not return an int.

  if(ButtonPressMillis> 10000)
  {
   MyServo.write(65);
   delay(300);
  }

So, if the switch is pressed and it has been more than 10 seconds after the Arduino was reset...

That does NOT seem like what you want to do.

You need to determine if the switch HAS BECOME pressed, not IS pressed. See the state change detection example. When the switch becomes pressed, record the time.

When the switch BECOMES released (not IS released), note the time. If the interval is greater than 10 seconds, move the servo.

You could have another if statement, after the body of the statement that deals with the state change, if you want to make the action happen 10 seconds after the switch became pressed, regardless of how long the switch is pressed, if that is the goal.

Your requirements are not really clear.

Yes, my goal is to toggle the servo to 65 degrees after 10secs or more of button press, then toggle back to 5 degrees after button is released. The LED and buzzer are just there to indicate button press.

I will look into it as soon as I get back home tonight.

The demo Several Things at a Time illustrates the use of millis() to manage timing. It may help with understanding the technique.

...R