Help - How to pause led blinking state

Hello Arduino Community!

I am a new member in need of some assistance in my code. Simply, I have a single red LED that must blink for some amount of seconds and then turn off for a few seconds as well. However, I want to connect a switch and code an interrupt so that during the blinking period, the code will pause (NOT pause outputs) but pause its current state, which in this case will be the LED continuing to blink indefinitely unless the switch is toggled again.

I have attached my code. Any help would be appreciated! Thanks!

ledPause.ino (796 Bytes)

http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

OP: Walk before you run.
You’ve used a lot of words that you obviously don’t understand yet. You’ll get there, but basic functional understanding will work in your favour.
Like MorganS said, look at the idea of a state machine as a start.
If you have a simple ‘switch’ your problem is easy, if you’re using a momentary pushbutton, then that state machine will help determine if the button is pressed, released,or changes ‘state’.

You must be very literal when programming- there’s a significant difference.

Ok thanks for the replies. I will look up state machine.

ninjaced:
I have a single red LED that must blink for some amount of seconds and then turn off for a few seconds as well. However, I want to connect a switch and code an interrupt so that during the blinking period, the code will pause (NOT pause outputs) but pause its current state, which in this case will be the LED continuing to blink indefinitely unless the switch is toggled again.

That probably makes perfect sense to you since you're very involved in your project and have a picture in your head of what it's supposed to do. But I (who am reasonably good at this Arduino stuff) could not code that from the description.

Does it mean that the "normal" state is to blink for a while, then stop for a while, blink for a while, then stop for a while, forever, but that cycle stops if a button is pressed and we go to the "interrupted" state and it resumes if it's pressed again?

Specifically, what doe this mean:

the code will pause (NOT pause outputs)

.

When you use the word interrupt, do you mean that in the computer science sense where it has a specific meaning, or just in the more colloquial sense of breaking the flow?

Sorry my typo
I was referring more specifically to detecting state-change detection.
That WHEN it toggles from high to low and vice versa.
Mea Culpa !

Yes that is correct. By "interrupt" I meant the state change (rising edge, falling edge, or both).

Does it mean that the "normal" state is to blink for a while, then stop for a while, blink for a while, then stop for a while, forever, but that cycle stops if a button is pressed and we go to the "interrupted" state and it resumes if it's pressed again?

Specifically, what doe this mean:

Quote
the code will pause (NOT pause outputs)
.

When you use the word interrupt, do you mean that in the computer science sense where it has a specific meaning, or just in the more colloquial sense of breaking the flow?

Normal state: blink for a while and then stop for a while forever (you're correct).

Button pressed during blink: program pauses on current state, in this case blinks forever unless button pressed again.

Button pressed during led off: program pauses on current state, in this case led stays off forever unless button pressed again.

Interrupt: I meant interrupt as in detection of (rising edge, falling edge, or both) to call the interrupt service routine (ISR) which somehow saves the current state and pauses (This is what I do not know how to implement)

Hope this clears things. Cheers.

You don't need interrupts. You only need to make sure there are no delay()s in loop(){}.

Then the loop will loop thousands of times per second. Rarely, on some of those times, it will be necessary to turn the LED on or off, depending on what has happened before. Even more rarely, you will find that the button has changed from the state it was on the previous loop. Then you can do something with that new information.

p.s. in this project, ditch the interrupt, it’s not necessary.