I'm trying to get my pinball solenoids to trigger from the Arduino UNO.
Currently I'm trying with just a push button & LED for testing.
When the button is pushed it should turn the LED on. If the button is still on for longer than 400ms then it should flash - 120ms off / 10ms on.
I've increased the final timings by x10 to see the LED flashing how I want it first.
Currently the code below acts as an elaborate toggle switch.
Yes. But what is wrong with it ?
For troubleshooting, you could start by incrementing a global (volatile) counter the interrupt service routine to see if is being called as expected by the timer. Print the counter every second or so in the loop().
The button triggers a timer interrupt in the setup. Enabling it to process instantaneously. Freeing up the loop(). Yes its a special way of C++ programming.
I’m an Electronics Technician by trade but I haven’t played much with microcontrollers since college.
I’ve updated the code. Now it processes the first if() statement instantaneously (needs to be for 1 second). Then it toggles between the other 2 if() statements if the button is still held down (which is good).
Your choice of timer0 is also not ideal on a Uno (ATmega328P) because this is also used for millis() which you are also currently using. Maybe chose another timer.