# Long button press proceeding counter just once

**URL:** <https://forum.arduino.cc/t/long-button-press-proceeding-counter-just-once/505307>\
**Category:** Programming\
**Created:** [January 31, 2018, 12:41am UTC](https://forum.arduino.cc/t/long-button-press-proceeding-counter-just-once/505307 "2018-01-31T00:41:35Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![lzanella](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lzanella](https://forum.arduino.cc/u/lzanella)\
**Post date:** [January 31, 2018, 8:36pm UTC](https://forum.arduino.cc/t/long-button-press-proceeding-counter-just-once/505307/3 "2018-01-31T20:36:13Z")

</div>

Thats excellent, and the example functions exactly as needed but when I use similar code the counter goes up constantly while button is held down and the else portion doesnt clear screen as written.

```cpp
/Button Variables
  //Fixed
const int buttonPin = 13;    // the number of the pushbutton pin
  //Variable
int buttonState = 0;        // Current state of the button
int counter = 0;            //Variable for counter function
int lastButtonState = 0;    //Previous button state

void setup()
{
pinMode(buttonPin, INPUT_PULLUP);        //initialize the pushbutton pin as an input:
}

void loop()
{
  Serial.println("Basic Encoder Test:");
  // initialize the LCD
  lcd.begin(); //Initialize Screen

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

                  
  if (buttonState != lastButtonState) {
    // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
    if (buttonState == HIGH){
    counter++ ; //Add to counter
    myEnc.write(0); //This redefines encoder to zero allowing the counter to force other if statement to reprint counter.
    lcd.setCursor(0,2);                // Cursor Position Col 1 Row 3
    lcd.print("MELTING...."); 
    lcd.setCursor(0,1);                // Cursor Position Col 1 Row 2
    lcd.print(counter);                // Strap Counter
    } else {
    
    lcd.setCursor(0,2);                // Cursor Position Col 1 Row 3
    lcd.print("              ");        // Print Blank Spaces to clear out "Melting..."
  }
  delay(50); //debouncing
  
  }
 

  

}

```

---

_[View the full topic](https://forum.arduino.cc/t/long-button-press-proceeding-counter-just-once/505307)._
