No. You aren't reading the code I posted and either understand it or slavishly copying it…
// Grab a copy of the variable
cli();
int myCopy = counts;
sei();
I spread it out so you can see.
Turn off interrupts.
Copy the volatile variable.
Turn interrupts back on.
I see that I left off a semicolon in the code in #11, sry. I hope it is the kind of error you can spot (or be made aware of by the compiler) and fix. Part of meeting us more than halfway - we try to be careful, but things like that will leak through.
Now your ISR looks like you have done some research. Looks good, but is fatally flawed… read the code below carefully, see the difference and understand why yours was close but no cigar.
Hint: srsly, you gotta put your finger on the code and read and "execute" it step by tiny step, every line. If you do that with your attempt, you will see why it just doesn't work.
Instead:
void interrupt_handler()
{
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
// If interrupts come faster than 200ms, assume it's a bounce and ignore
if (interrupt_time - last_interrupt_time > 200)
{
++counts;
last_interrupt_time = interrupt_time;
}
}
Only move your time stamp forward if you actually did anything based on the passage of that 200 ms.
BTW, 200 ms is an eternity. Most switches and even using a paper clip as a switch will settle down much faster.
You could do some experiments with your switches and see how large that lockout period has to be so you get one count per button press.
So now you are into interrupts, when you may have been able to totally avoid them.
Don't say I didn't warn you!
a7