Serial.print - send it just once

Hi,

how can I restrict that Serial.print(); goes to serial just once?
For example, let me explain on this part of 'button code'-

void loop() {
     // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
   [color=red] [b]Serial.println("HIGH");[/b][/color]
delay(50);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);


}}

So, if I press button, LED goes ON, but on serial I will get message HIGH in new lines every 50ms.
What would I like to get is that while button is pressed, LED goes HIGH but Serial prints 'HIGH' just once instead of constantly printing while I'm holding button.

I hope you will understand me :slight_smile:

I hope you will understand me

I hope you will understand me when I tell you AGAIN to look at the state change detection example.

You do NOT want to take action when the pin IS HIGH. You want to take action when the pin BECOMES HIGH.

Paul,

thank you, I realized now what were you telling me before.
For others that maybe wanted to know this, here is the link: