Is it possible to assign a random color to a string of leds? I have a string of 10 WS2812 leds, and they can be any color I stated in the array With the FastLed lib a color can be a name.
colorLed = {Red, Blue, Green, Purple}; I would like to random pick a color for each led separate, not the whole string just on one color. It's not a problem is two or more leds have the same color.
I tried something like this: trying to assing a color to a number, and giving the led a random number. The code doesn't validate, it's not possible to combine an int with a random number (at least not the way I tried)
#include "FastLED.h" #define NUM_LEDS 10 CRGB leds[NUM_LEDS]; #define DATA_PIN 2 long randNumber; long randNumber0 = CRGB::Red; long randNumber1 = CRGB::White; long randNumber2 = CRGB::Blue; long randNumber3 = CRGB::Red; long randNumber4 = CRGB::White; long randNumber5 = CRGB::Blue; long randNumber6 = CRGB::Red; long randNumber7 = CRGB::White; long randNumber8 = CRGB::Blue; long randNumber9 = CRGB::Red; #define INTERVAL_MESSAGE1 5000 unsigned long time_1 = 0; void setup() { FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS); Serial.begin(9600); } void loop() { if (millis() >= time_1 + INTERVAL_MESSAGE1) { time_1 += INTERVAL_MESSAGE1; leds[0] = randNumber.random(0,9); leds[1] = randNumber.random(0,9); leds[2] = randNumber.random(0,9); leds[3] = randNumber.random(0,9); leds[4] = randNumber.random(0,9); leds[5] = randNumber.random(0,9); leds[6] = randNumber.random(0,9); leds[7] = randNumber.random(0,9); leds[8] = randNumber.random(0,9); leds[9] = randNumber.random(0,9); FastLED.show(55); } }