Author Options:

Arduino Pushbutton interrupt? Answered

So I've hooked up my Christmas lights to some solid state relays and hooked those to my Arduino and I have some interesting patterns of lights that I can make. But I would like to be able to turn the lights on and then press a push button and have one light pattern start and then press that same button again and get a second pattern and so on. I've gotten that to work, the only problem is, the patters are quite lengthy (5-10 seconds) and I don't want to have to hold the button until the pattern is over. So how do I use the interrupt function (or one like it) to stop the function and start a new one as soon as the button is pressed?

2 Replies

steveastrouk (author)2013-12-09

You could use an interrupt, but lets see the code first.

Select as Best AnswerUndo Best Answer

mpilchfamily (author)2013-12-08

Show your code.

Interrupts are not what your looking for. What you can do is create a variable to track the number of presses. So when the button is pressed add 1 to the variable. Then do a comparison of the variable so if the variable is greater than the number of patters you have store 1 to that variable. Then check the variable and call to a separate void which has the light pattern. There is more to it but you'll be able to figure it out i'm sure.

Select as Best AnswerUndo Best Answer