int triger = 1; int button_pin = 12; bool flag = false; int trig(){ triger=(triger+1)%2; return triger+1; } void setup() { // put your setup code here, to run once: Serial.begin(9600); pinMode(button_pin,INPUT_PULLUP); } void loop() { // put your main code here, to run repeatedly: if(digitalRead(button_pin)==0){ if(!flag){ flag = true; Serial.println(trig()); delay(4000); } }else{ flag = false; } delay(10); }