Go Down

### Topic: LED Strip, random pattern and color (Read 502 times)previous topic - next topic

#### Twiggernaut

##### May 29, 2019, 02:57 am
So this is a two part question. I'm very new to coding and have been mostly copy pasting my functions with a very basic understanding of how they work.

Problem 1:

I would like to randomly select a pattern from a predefined list of patterns. I have been reading up on arrays but i'm not sure how to make it work for my functions.

Problem 2:

I would like each pattern to randomly select a color from a list of colors.

Essentially, I would want this to cycle through the random patterns with random predefined colors.

Here is the code without the actual pattern functions (Exceeds character limit)

#include "FastLED.h"
#define NUM_LEDS_A 37
#define NUM_LEDS 37
CRGB strip[NUM_LEDS_A];
#define PINA 6
#define BRIGHTNESS 30

void setup() {
FastLED.setBrightness(BRIGHTNESS);

}

void loop() {

//list of function commands that cause a pattern

TwinkleRandom(500, 10, false);
Twinkle(255, 0, 0, 50, 50, false);
NewKITT(255, 0, 0, 2, 10, 50);
Strobe(255, 0, 0, 10, 50, 10);
CylonBounceLong(0, 0, 255, 4, 10, 100, 5); // blue
MeteorRain(255,255,0,2, 64, true, 10);//yellow
RunningLights(255,0,0,50); //RED
colorWipe(0,255,0, 10);
rainbowCycle(10);
theaterChase(255,0,0,50);
}

#### Grumpy_Mike

#1
##### May 29, 2019, 04:58 amLast Edit: May 29, 2019, 05:01 am by Grumpy_Mike
How to use this forum

Once you have set a pattern going how long do you want to run it for?
Would this be a fixed number of cycles of that pattern or for a fixed amount of time. The first is easy the second not so.

If it is the second then you have to convert all your pattern code into a state machine structure, this is a step up in difficulty than the normal code you are just getting to grips with. The essence of this is described here:- http://www.thebox.myzen.co.uk/Tutorial/State_Machine.html

If just a fixed number of cycles then just choose one of those functions at random using the "switch / case" structure. Look it up in the 'reference' entry in the Arduino's software help menu.

Quote
I would like each pattern to randomly select a color from a list of colors.
Then you have to change the code in each of those animations to do that. The list of colours will be in an array and you use a random number for the index of that array.

#2