Help me correcting my program..

I wrote a small program in which a push button is connected to pin 2 of the Digital.

I want to print the increments of +1 each time I press the button.. At the same time I wanted to blink the LED connected to PIN 13

But the problem is that I am using a delay of 300 for the print and the LED is also taking that delay..

So when I press the button and leave the LED state is HIGH for 300

But I want the LED to just stay High for about 10 millisecond..

How do I do this

I have attached the program below..

int buttonPin = 2;
int buttonState = 0;
int i = 0;
int ledPin = 13;

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

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

 if (buttonState == HIGH) {
     digitalWrite(ledPin, HIGH);
     i ++;
  else {
    digitalWrite(ledPin, LOW);

Look up the millis() function. That will allow you to do what you want.

However, what happens when you take a bit longer while pushing the button? Because you're not looking at an edge change, you're just looking for state and in that case as long as your finger is on the button the counts will add up.

yes as long as I am keeping the button pushed the counter counts every 300millisecond and the led keeps glowing…
But as same as before… As soon as I leave the button the led goes off lil later.That is 300 millisecond