Hoping someone can point my brain in the right direction from a high level perspective. I'm teaching my son the basics and I think I may have cornered myself in my attempt to expand on his desire to learn by building upon his questions. We started off with the standard 'blinky' LED, then he asked about a second LED and alternating flashing. No problem there and I was happy to follow along to keep him interested. Then the next question was how can I add a button to turn the flashing LEDs completely on or off. I thought no problem but quickly ran into the issue that when the LEDs flash the flash sequence has to run in a loop continuously even while scanning for button changes of state but I must escape the flashing loop when they are suppose to be off. I am beginning to think that I may have breached the basics and jump a bit to far ahead. But I think he can understand if I can wrap my head around it and explain it to him.
My question is from a high level perspective (outline) how would I go about accomplishing scanning for button state change while at the same time keeping the flashing loop running while doing so and turning off the flashing loop when its suppose to be off?
I looked at last state variable, but the last state of the button will always be a HIGH to trigger a change of on or off.
Maybe interrupts for the button? Is there any such thing as threading for the flashing loop?
Thanks