getting button input on long delay


I'm new to Arduino but I have to admit I like it very much.

Here is my problem: I'm building a "Xmas tree light system with different patterns using leds.

I built a couple of patterns and everything is working great so far. the problem i'm having is with the push button i'm seting up to change patterns.

some patterns have a long delay (I have 6 groups of 5 leds connected to the PWM pins to make them fade in/out).

some delays can got up to 5-6 sec. and in the main loop(), that is to long to catch the digitalRead() on the button pin.

I had 2 different senarios: #1: make my own delay function and read the button pin at every cycle or so. #2 is by using a interrupt on the button had force the change on patterns.

Is there someone that could shead some light (no pwond intended) on this problem of maybe give a comment on a better way to build the button part ?

thanks for any inputs.

Jeff C.

You almost certainly don't need interrupts, but you could have a look at the "blink without delay" example/tutorial.
Maybe you could post your code.

There is an example provided, called Blink Without Delay, that you should take a look at. Basically, you need to separate the what to do (read button, turn on light, turn off light, etc.) from the when to do it. Then, just like you would do it with a watch, see if it is time to turn the LED(s) on or off, etc., after reading any switch or sensor input.

ok, thanks for all the feedbacks.

i'll look at it.

For posting code, its not pretty, (doing this fast so I can build the small tree in time for the decorations :wink: )

its quite long too.. is there a to post code here or is something like pastebin used ?


Jeff C.

(doing this fast so I can build the small tree in time for the decorations

I'm afraid interrupts are unlikely to shorten the development process.