I am using the Neopixel library to control four independent LED strips. I would like each strip to be a different colour but the random value and seed is consistent for each strip.
How do you suggest I modify to the code such that each buildings color is independent of the others?
// Sets strips to (R,G,B, color load time)
colourFill(Building1.Color(random(0,255),random(0,255),random(0,255)), 1);
colourFill(Building2.Color(random(0,255),random(0,255),random(0,255)), 1);
colourFill(Building3.Color(random(0,255),random(0,255),random(0,255)), 1);
colourFill(Building4.Color(random(0,255),random(0,255),random(0,255)), 1);
I am using the Neopixel library to control four independent LED strips. I would like each strip to be a different colour but the random value and seed is consistent for each strip.
How do you suggest I modify to the code such that each buildings color is independent of the others?
You want random values in the range 0 up to 254 maximum?
And after each controller reset you want to start over with the same "random" values created with same seed value?
You see, this code results with the same problem. All four LED strips are emitting identical colours. I switched the positions of RandN and got the same result.
I am using the Neopixel library to control four independent LED strips. I would like each strip to be a different colour but the random value and seed is consistent for each strip.
How do you suggest I modify to the code such that each buildings color is independent of the others?
What is expected is that the colors displayed by the four strips are not only random, but also different from each other
They won't actually be random but only pseudo random. You can improve that somewhat by using the randomSeed() function perhaps fed by the value from a floating analogue input.
If you want each strip to be a different colour then you need to check that the colour has not already been generated by the random() statements (unlikely) and if so choose another colour.
You didn't actually answer my questions about what is happening with the current code.
void colourFill(uint32_t c, uint8_t wait) {
// This script programs all LEDS on a strip to have the same color.
You call this function. If it does what the comment says could it be the basis of your problem ?
I have been asking repeatedly what the best method is for generating MULTIPLE random values during the SAME execution of a loop.
I do not think I can be more verbose. I am aware that the OP code was problematic, but I assumed that my readers would be capable of considering the original code in light of my request. I seem to have overestimated my audience.
First, colourFill is NOT a problem because it takes the values assigned in the MAIN loop as input. I could write independent values as input and achieve the desired effect, but the colors would NOT be random.
Second, randomseed does not have any purpose in this program because RandomSeed sets the value of all Randoms within an execution. For example, when Seed is A then all randoms per cycle are based on A (that does NOT mean that each random is different from the other). The random value is the same during the same execution of the Main and can be changed by a seed, but all references to random will be calling on the same value.
First of all...that came off a little rude...
Second of all, if what you want is 4 strips of different colors, then colourFill DEFINITELY IS your problem!
Here is another hint!
void colourFill(uint32_t c, uint8_t wait) {
// This script programs all LEDS on a strip to have the same color.
Read that comment, then check what your function ACUTALLY does...
Another hint...
// Sets strips to (R,G,B, color load time)
colourFill(Building4.Color(255, 0, 0), 1); //red
Run this code, now tell me, do ALL 4 of your strips turn red, even though I only set '1' strip? WHY?!!?!
Ps991 - Struck gold. In my haste, I forgot that repeating the for loops within the same colourfill script with the same random input would pull the same colour value.
You were right that in identifying colourfill as the problem. The program now performs as expected. I apologize for expressing my frustration so crudely.
If you want them random but different from each other, one option is to use the HSB model. Pick a random angle between 0 and 2*PI, offset each strip by PI/2 degrees - that gives you the hue for that pixel. To produce RGB from the hue, use sin() and offset each component by a third (of 2PI).
This means that pixels 0/2 and 1/3 are complementary colours. If you are jumping around randomly, it perhaps won't be obvious.
Your pixels will have a mostly constant brightness, and the net colour of the sum of them will always be white (or close to).
Ps991:
If you want them random but different from each other, one option is to use the HSB model. Pick a random angle between 0 and 2*PI, offset each strip by PI/2 degrees - that gives you the hue for that pixel. To produce RGB from the hue, use sin() and offset each component by a third (of 2PI).
If I correct your code to what I think you intended, to get it to compile, it does behave in an "interesting" way.
I observe that the probability that an individual R, G or B value will be 0 or 255 is more than twice as great as the probability of the value being 1 or 254, with other values having lower probability.
Typically, the distribution comes out looking like this: