#define BUTTON_PIN 33
int buttonState = LOW; // button is wired : released -> LOW
// let's create a variable to count the number of presses
int counter = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
byte newButtonState = digitalRead(BUTTON_PIN);
// button state has changed
if (newButtonState != buttonState) {
// only enter this loop if the button state has changed
buttonState = newButtonState; // update state variable
// print the new button state
if (buttonState == HIGH) {
counter += 1;
Serial.print("button pressed: ");
Serial.println(counter);
} else {
Serial.println("button released");
}
}
// delay as we want to see bouncing in the serial monitor
//delay(10);
}