Is it possible to partition an arduino in a way that will allow the

Is it possible to partition an arduino in a way that will allow the loading of multiple LED applications. I am very new to arduino, and thus am not able to write anything useful, but I have managed to find some good code which I have been able to make small changes to in order to get it to work right (especially with the microphone that I purchased from ebay)

For example, this is the code that I am using to have the WS2811 LED strip, flash random colors in response to audio detected by the mic. https://drive.google.com/file/d/0B-yA8G8qRq8NY2g0UmNGaTF6Njg/edit?usp=sharing

In addition to that, I have seen some that will also create interesting lighting patterns, or slowly transition through all possible colors.

Is there a way to essentially load 2 or 3 different LED scripts, and then use a button to switch between them? (e.g., mode 1 will have it respond to audio picked up from the mic, and mode 2 will have it transition between a set of colors, and mode 3 will do something like a ripple patters from the center LED, going outwards)

This problem stumped me too as I was learning, I will use pseudo code below to explain:

//Say you have two LED patterns that you want to show

//mode is the variable that will change which LED pattern is displayed
byte mode = 0;

//Now create your patterns/functions
void fill_RED(){
fill_solid(NUM_LEDS, CRGB::Red);
}

void fill_BLUE(){
fill_solid(NUM_LEDS, CRGB::Blue);
}

//Now to read your button
void read_BUTTON(){
//insert your button read code
//if button press detected, mode = mode + 1;
}

//then in your loop(), do something like this

void loop() {
read_BUTTON();

switch(mode) {
case 1:
fill_RED();
LEDS.show();
break;

 case 2:
 fill_BLUE();
 LEDS.show();
 break;

 }

}

Switch case statements, they’re GREAT! http://arduino.cc/en/Reference/SwitchCase

@Jon_Burroughs
I saw some examples like that, the issue I ran into is that they don’t exactly allow you to take something like the audio + LED script or other complex ones, and copy and paste them under one of the modes, and then take another script that you got from somewhere else and paste it under a different mode, and use a button to switch between the 2.

It’s not as easy, as you say, cut and paste. Have you checked into Funkboxing? Google for that site, there is a great resource for code you can learn from. The code examples there are something nearly everyone has played with at one time or another.

there is the option of doing literally as you suggested and use a switch to change to different modes based on readings from a sensor or serial input. You could write or copy different functions and just call them depending on the mode you are in.

You can’t “partition” an Arduino (or any micro processor as far as I know.) However, you can load up more than a single sequence or pattern on to it. Funkboxing is a great example of that. Using a button to select which sequence to display is one way to switch between them. Another way is to set a fixed timer that automatically switches between them.

I recommend this for a starting point on how to bash two sketches together with a mode switch:

Take sketch1. Rename “setup” to “setup1”, and “loop” to “loop1”.

Take sketch2. Rename “setup” to “setup2”, and “loop” to “loop2”.

Now make a new sketch, called “Combo”. Paste in all the relevant existing code from sketch1 and sketch2.

At this point, Combo has NO setup or loop of its own, so add them, like this:

void setup() {
// setup both
setup1();
setup2();
}

void loop() {
// read the mode setting from…somewhere
int mode = howeverYouChooseYourMode();

// now call the appropriate loopN
if( mode == 1) loop1();
if( mode == 2) loop2();
}

Now let me say there are a dozen ways this might not work-- it all depends on the sketches you’re trying to combine!

But this is the basic idea. You have some variable that controls which thing do to next, and then some little set of ifs or switch/case that dispatch to the correct worker function (e.g., loop1, loop2) to do one little piece of work. Each worker function does one piece of work and then returns back to the controller function (the new master ‘loop’).

Once you have that structure, you can play around a lot with how the controller loop choose what to call next: it could read a push button, it could check the timer (millis()) and randomly switch workers every 10 seconds, it could have a preprogrammed schedule, or any simple or complicated thing you can imagine.

But the first step is diving things into “worker” functions (loop1, loop2) and a “controller” function (the new ‘loop’).