Push Button Switch, To Blink Led.

I want to make A push button, that when held down it would make, one led go on for 3 sec. then go off. Even if the switch is still held down.....

The code, I tried to make work is this. I thought to use A (while(.....)). It didn't work.

int buttonPin = 2;     // the number of the pushbutton pin
int ledPin =  13;      // the number of the LED pin

int buttonState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(buttonPin, INPUT);   
}

void loop(){
  buttonState = digitalRead(buttonPin);
  if (buttonState == HIGH) {   
    digitalWrite(ledPin, HIGH);
    delay (300);
   while(buttonState == LOW);
  }
  else {
    digitalWrite(ledPin, LOW);
  }
}

Try: Note, add code to de-bounce your switch, I'll leave that up to you.

int buttonPin = 2;     // the number of the pushbutton pin
int ledPin =  13;      // the number of the LED pin
boolean ledOn = false; 
int buttonState = 0;

void setup() {
  pinMode(ledPin, OUTPUT);     
  pinMode(buttonPin, INPUT);
  digitalWrite(buttonPin, HIGH);   // turn on pullup
}

void loop()
{
  buttonState = digitalRead(buttonPin);

  if (buttonState == HIGH && ledOn == false)
  {   
    digitalWrite(ledPin, HIGH);
    ledOn = true;
  }
  
  if (ledOn == true)
  { 
    delay(3000);
    digitalWrite(ledPin, LOW);    
    ledOn = false;
  } 
  
  while (digitalRead(buttonPin))
  {
    ;  // stay here as long as the button is pushed i.e. HIGH
  }
}
    delay (300);

300 milliseconds doesn't equal 3 seconds.

   while(buttonState == LOW);

You only arrive at this point in the code because buttonState is HIGH, how could it then be low if you don't read the button again?