How to stop a loop until I need it to be checked again?

void loop()
{
  
  if(digitalRead(buttonpin) == HIGH)
  {
    Serial.println("button pressed");
     delay(2000);  
  }
  else{
  Serial.println("button not pressed");
  delay(2000);  
    }

I would like to make code so that when the button is pressed it breaks the loop until the button is released and not have a series of "the button is pressed" or "the button is not pressed" on the monitor.

Studdy the "state change" sketch from the examples menu in the IDE.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.