i want do that: when i press button 1 time, program does what i want and when i press 3 times, program does what i want. but interrupt code doesn't work as i want. i see always sayac= 1 in serial monitor although i press button 3 times.actually, i don't know where i should write delay. my codes are below. Have you an idea?
I'm not sure that you need to use interrupts at all.
But if you do then almost ALL of the code you now have in your ISR must be taken out and put into loop().
There should be NO delay() and NO Serial.print() in an ISR.
Make it like this
void stop_interrupt(){
sayac++;
}
And you can read the value of sayac in loop() like this
void loop() {
noInterrupts();
latestSayac = sayac;
interrupts();
// do stuff based on the value of latestSayac
}
Humans push buttons at a very slow speed. You will almost certainly be able to detect the buttons with a simple digitalRead() called from loop()
In general do not use delay() to manage timing as the Arduino can do nothing while the delay() is in progress. Use millis() for timing as illustrated in several things at a time.
An interrupt is a doorbell ringing while you are cooking dinner. It does NOT make the partially prepared meal disappear, or place a call for chinese takeout.
You go answer the door, tell the person to go away, and go back to cooking dinner. You do not stand at the door chatting away for 2 hours, while dinner burns.