#define button 2
int cnt = 0;
bool state = 0;
int last_state = 0;
void setup() {
Serial.begin(115200);
pinMode(button, INPUT); //configure to input mode
}
void loop() {
state = !digitalRead(button);
if(state != last_state){
if(state == 0){
cnt += state;
Serial.println(cnt);
}
delay(40);
}
last_state = state;
}