Using one Arduino to control multiple LED functions

So I want to use RGB LEDs as interior ambient lighting in my car. It currently have footwell, dash, and backlit cupholders, but I want to manually control what color is displayed at night. As far as I'm aware, you can only carry out one setup and one loop function through an Arduino which simply translated means I can only have it display one color or animated sequence while booted up.

My real question: Is there a way I can setup a momentary button to cycle through different loops/functions to change to preset LED colors/animations? The FastLED library that I'm using uses void loop to carry out LED sequences or simply continuously display a color/colors. Any input to help me with this project is greatly appreciated!!
Below is an image of areas of LEDs I want to control:

Yes, but the animations must not block reading of the input which in practice means no for loops, no while loops and no delay()s in the animations

Reading the input button is easy but you need to detect when the button becomes pressed rather than when it is pressed

See the StateChangeDetection example in the IDE

1 Like

I think it can be quite simple to do: one or more pushbuttons can be sensed in intervals, settings can be stored in eprom-memory so when you start up the next time it can read all settings, prior to operating.
Simple things like this can be programmed in just a Atmega328P with a crystal and two capacitors, using your arduino as ISP-server..

Makes no sense. Arduino is fast enough so you can update many colours one after another and you wont be able to tell the difference because it much much much much much faster than human eye

Correct.

Clear nonsense. :roll_eyes:

This is all about programming. Programming or "coding" is all about making it do exactly what you want it to do.

The structure of the "setup()" and "loop()" is in no way any form of "limitation" whatsoever, just a very neat encapsulation of two aspects of a task; preparing all the necessary ingredients, followed by the repetitive steps involved in executing the task which includes all the decisions involved in determining which part of the task to perform next.

It forms a loop because in most cases the overall task is never "finished". It goes back again and again to look for the next step in the process. Each step is an alternate path through the loop. based on decisions according to the "state" of the systems, thus it is called a "state machine".

Where did you come from? :astonished:

1 Like

Not exactly what I meant... what I meant to say is using the LED library, since it uses the loop for the desired sequence, color, etc., you cannot program multiple different sequences to occur by choice (i.e. using a toggle button) without the loop reading and displaying them all in a chain rather than select which ones you want individually. What I wish to accomplish is for the arduino to display a specific color all the time until I press a button to tell it to switch to a different color. But since the library uses the void loop to continuously display the color, it seems like that is the only function it can carry out. Like I said, I'm relatively new to programming so if there's a step or something I could use to get around this, that is what I'm looking for

Hello
Take some time and study the design of a FSM, button- and time handler. These software modules will help you to get the project goal.
Have a nice day and enjoy coding in C++.

1 Like

You have something badly confused there. :astonished:

Firstly there is no such thing as a "void loop". The term "void" is a qualifier - it selects how the following function - "loop" is one such function - behaves in respect of whether or not it returns a value directly when called. "void" means it returns nothing.

Secondly, the "NeoPixel"s require no data to hold their colour, you only "refresh" the data to them when you need to change their colour - and you have to refresh all of the pixels every time so the term "individually addressable" is somewhat of a misnomer.

So a sequence of changes requires code to send a complete new pattern - even when some or most of the pattern is the same as the previous - on a timed basis in order to animate it. How libraries do this will vary and some (perhaps most) will tie up the processor, internally using delay() while they complete the pattern sequence. This is a specific limitation of the library, completely unrelated to the "loop()" function.

Overcoming this requires using library functions only to implement single pattern steps so that your code can make the decisions to take the next step or if the button has just been pressed, to change to a different pattern.

The FastLED library doesn't use loop(), it's the other way round: loop() uses the FastLED library.

By changing loop() you can make the LEDs do whatever you want. For example, you might store the pattern for eight different colours in your program, and when the button becomes pressed, it moves on to the next pattern in a circular fashion. When the button remains unchanged, no new pattern is sent, so the LED colour remains the same.

That's the basic approach. Study the code you've got to see how the colour is controlled, and also take a look at the State Change Detection sketch in File | Examples | Digital.

Firstly there is no single LED library, there are many out there, some are better than other. You absolutely can separate loop execution to cover different sequences because as I said, Arduino is very fast. You haven’t posted any code or spec for your board or detailed description of what you want to achieve, but it very likely you can do it with single board

I came from nowhere, but now i live in the Netherlands... or what do you mean exactly?
What i understand is that it must be a controllable lightshow with adjustable colors or patterns.
Latest setting stored and read at startup... Nothing special IMHO...

Kees

Your reply was singularly puzzling.

Suggesting building a "bare-bones Arduino" does not seem to be particularly helpful; a Pro Mini clone is the most practical device to start with for constructing a basic control system.

And whatever is "using your Arduino as ISP-server" supposed to mean?

Well, let me explain: You can make a small board with a Atmega328P, two capacitors (lets say 22pF, depending on the type of crystal, but the normal througholes work with 22pF) and a 16mHz cristal... that will cost you roughly 2 - 3 dollars maybe.. This board has all posibilities to drive all kinds of periferals, like a 2 meter string of WS2812b leds... But you have to get the program in it..
On a Arduino (like a UNO) is a 6 pole connector which is a ISP port.. On that little board you made you also have all points for a ISP-connector already... Thats how a Atmega328P is build... So when you connect both ISP ports 1 to 1 except for 5, which has to be connected to point 10 (on a Uno) all hardware is settled to program..
Ok, you still need a Uno for it but you don't have to put it to work in your project an can use it to develop more gadgets..
Ok, the programming... first you have to program the Arduino as ISP, this is in the examples..
then you can program the Atmega on the board.. If this is a fresh processor you have to bootload it first (in IDE: Tools> Burn Bootloader) Then you can upload your program to the Atmega: with SHIFT pressed you click op the uploadbutton (>) The program will be stored in the processor.. It will proceed a bit slower than when you program the Arduino (uno)
Clear?

But I can get a properly assembled Pro Mini - albeit a clone but containing the same grade of components as far as I know - for the same price. And it would have the bootloader on it so I do not need the ISP, just a USB-serial interface module for a similar price.

Why would I want to go to the trouble of getting the separate parts and making a PCB - or getting through-hole parts and using stripboard to construct a much bigger assembly?

Sure, people come here often enough doing this on the "Look what I did all by myself" ego-trip, but as best I can see, the OP just wants to do something for his car. Nor is he going into full-scale manufacture as best I can determine. :roll_eyes:

I frequently advise that a UNO is not a good form for most practical projects. If a readily-available UNO-format "shield" completes it, fine, but otherwise a pain to use. Nano for USB connectivity.

You seem to be off on a quite different "tack" to what this thread is all about and I am wondering why. :grimacing:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.