const int BUTTON_PIN = 2; // digital input pin connected to button
bool buttonPressed = false; // flag to indicate if button has been pressed
void setup () {
pinMode (BUTTON_PIN, INPUT);
}
void loop () {
bool buttonState = digitalRead (BUTTON_PIN); // read current state of button pin
if (buttonState == HIGH && !buttonPressed) {// detailct rising edge
// do something when rising edge is detailed
buttonPressed = true; // set flag to indicate button has been pressed
}
else if (buttonState == LOW) {// reset flag when button is released
buttonPressed = false;
}
// other code here
}