digitalRead question!

hi everyone. i need a help for my new project. it's quite simply but i don't know how to make it works fine...
Arduino make a digitalRead on pin2 and if there's a high level (1) it increment a variable (variable++;). the problem is that if the button continue to be pressed, the sketch continue to increment the variable.
is something about the coin counter... there's a method to read only the pulse signal (switched by a pushbutton) with not continue reading the state during the same pressure?

hope i was clear and thanks in advance for your help!
Valerio.

So, make the variable increment when the switch goes from not pressed to pressed, not just when it is pressed.

Try something like this:

int couter=0;
boolean pressed=false;

if(digitalRead(pin)==HIGH&&pressed==false)
{
     counter++;
     pressed=true;
}
if(digitalRead(pin)==LOW&&pressed==true)
{
     pressed=false;
}

AWOL:
So, make the variable increment when the switch goes from not pressed to pressed, not just when it is pressed.

Could you make me an example please?

Patouf:
Try something like this:

int couter=0;

boolean pressed=false;

if(digitalRead(pin)==HIGH&&pressed==false)
{
    counter++;
    pressed=true;
}
if(digitalRead(pin)==LOW&&pressed==true)
{
    pressed=false;
}

ok, i've tried but there is a problem, if i leave the button pressed it continue reading (and adding)... it shouldn't do!
i need a sketch that count only one time for pressure and stop reading after the button will be realized and pressed again!
Thanks again guys!

How is the button wired ? From where, to where and are you using a resistor in the circuit ?

@Patouf, scusmy, i've tried incorrectly, THE SKETCH WORKS perfectly for me! thanks to everyone! (i've tried to edit my message but i'had lost my internet connection!)

so, problem solved, it JUST counts the pressure even if u leave the button pressed for some time after the push!

Thanks again!

Button that does not bounce is pretty valuable. What button and where did you get it?

A normal pushbutton for the PCB.

Buttons vary. Does your code have one or more delay() in it?

GoForSmoke:
Buttons vary. Does your code have one or more delay() in it?

no @GoForSmoke, it hasn't BUT i made a mistake! the sketch works correctly, the first time i've forgotten a piece of sketch! XD