Interrupts LEDs and Displays


I am relatively new to arduino but have a basic understanding of C. I am trying to program up a device that allows me to do the following:

I want to be able to display various active patterns on several addressable LED strips. The coding for this is all complete.

I have a small OLED display (I2C) which I want to use to display which pattern or program is active on the LED strips.

I want to have an input that allows me to cycle between the patterns of LEDs and update the display accordingly.

Can anyone help in terms of how i go about programming the interrupts correctly? Each LED program is a function which can be called. However, in order to achieve the desired effect, there are small delays in some functions (eg to permit movement of light up and down LEDs at a desired rate). What's the best way of cycling through these functions, whilst ensuring the interrupts are pretty instantaneous from the user's input?

Using Adafruit libraries (neopixel) and Adafruit SSD1306 libraries.

Thanks in advance for your help.

This doesn't need interrupts.

If you are thinking you can interrupt one function and exit it from there you're mistaken. The interrupt would return to the place in the code that was interrupted.

If you want to be able to stop the lighting sequence then you'll need to rewrite the sequences so that they are non-blocking.

Ok thanks Delta_G. In which case I guess it's a case of polling for the input within each of the LED patterns? Is there a best practice for ending a function early?


Have a look at the demo Several Things at a Time

You don't need to (and should not) poll the input "within each of the LED patterns". Just poll the input in a function for that purpose and ensure that the functions for the LED patterns allow loop() to repeat frequently (hundreds or thousands of times per second).

I say "should not" because duplicating code just increases the scope for errors and makes everything harder to manage.


Thank you Delta_G and Robin2 for your inputs. Just about getting there!