Change LED Color for random sequence

I have a snowflakes script that will basically light and dim the leds at random in a certain interval, the led's will only light in white and i want to be able to change the color. I tried editing a couple sections of the code to input for example the color red(255,0,0) but the color would not change. Any suggestions on where i need modify it, thanks.

bool Snowflakes(uint32_t c, uint8_t wait)
{
  
  
  // variables that will be remembered between successive calls
  // start time for delay
  static unsigned long startTime;
  // indication if Rainbow is in progress
  static bool inProgress = false;

  // if Rainbow is not yet in progress
  if (inProgress == false)
  {
    // indicate that it's in progress
    inProgress = true;
    // set the start time (for delay)
    startTime = millis();
  }

  // if a 'delay' period has lapsed
  if (millis() - startTime >= wait)
  {
    // Setup the pixel array
    int pixel[PIXEL_COUNT];
    for(int p=0; p<PIXEL_COUNT; p++){
    pixel[p] = random(0,255); 
    }

    // Run some snowflake cycles
    for (int j=0; j<200; j++) {

    // Every five cycles, light a new pixel
    if((j%5)==0){
    strip.setPixelColor(random(0,60));
    }

    // Dim all pixels by 10
   for(int p=0; p<PIXEL_COUNT; p++){
   strip.setPixelColor(p, pixel[p],pixel[p],pixel[p] );
   pixel[p] =  pixel[p] - 10;
   }
   
    
    strip.show();
   
    delay(wait);
    }
      
  
    // 'reset' the start time for the delay
    startTime = millis();
    // next time that 'delay' has lapsed, use next pixel
    pixNum++;
  }

  // if all pixels done
  if(pixNum == strip.numPixels())
  {
    // color wipe finished
    inProgress = false;
  }

  // indicate the status to caller
  return inProgress;
  }

would help to have the complete code and wiring diagram.

      pixel[p] = random(0, 255);

You initialize each pixel to a value from 0 to 254.

     // Dim all pixels by 10
      for (int p = 0; p < PIXEL_COUNT; p++)
      {
        strip.setPixelColor(p, pixel[p], pixel[p], pixel[p] );
        pixel[p] =  pixel[p] - 10;
      }

You use the same value for Red, Green, and Blue so that explains why your pixels are all white. If you want different colors, you could make 'pixel' an array of colors instead of an array of integers. Initialize the Red Green and Blue parts of each pixel to different values. Dim the three parts of the pixel separately.

Here is the full code.

#include <SoftwareSerial.h>

#include <Adafruit_NeoPixel.h>
SoftwareSerial BT(10, 11);
#define PIXEL_PIN      6    // Data Pin of Led strip 
#define PIXEL_COUNT    60   // Number of LEDs in the strip
#define BRIGHTNESS     100    // use 96 for medium brightness
#define SPEED          0    // Speed of each Color Transition (in ms)
#define IMMEDIATELY    0    // Transition happen instantly
#define RAINBOW_SPEED  100    // Rainbow Transition speed
#define WIPE_SPEED 2     // Sweep animation delay.
// number of pixel to change
byte pixNum;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

enum MODE
{
  
  RedSnowflake,
  BlueSnowflake,
  GreenSnowflake,
  PurpleSnowflake,
  INITIAL,
};

MODE mode = INITIAL;

void setup() {
   
  strip.begin();
  strip.setBrightness(BRIGHTNESS);
  strip.show();    
   
   BT.begin(9600);
   
   BT.println("Connected to Arduino");
    

  strip.setBrightness(BRIGHTNESS);  
   

  strip.begin();
  strip.show();

}

char a;

//  VOID LOOP

   void loop()
{

if (BT.available())
  {
    char a = (char)BT.read();
    switch (a)
    {
      
      case '&':
        mode = RedSnowflake;
        BT.println("TURNING LEDs RAINBOW");
        break;
      case '*':
        mode = GreenSnowflake;
        BT.println("TURNING LEDs RAINBOW");
        break;
      case '(':
        mode = BlueSnowflake;
        BT.println("TURNING LEDs RAINBOW");
        break;
      case ')':
        mode = PurpleSnowflake;
        BT.println("TURNING LEDs RAINBOW");
        break;
        
      // other cases here
      
      
    }
  }

  switch (mode)
  {

     case INITIAL: if(strip.Color(0, 0, 255) == false)
    {
  
    // done with colour wipe
    Serial.println("colorWipeNonBlock finished");

    // reset pixNum so other functions start from 0; only if needed
    pixNum = 0;
    }

      case RedSnowflake: if(Snowflakes(strip.Color(255, 0, 0), 40) == false)
      {
  
    // done with colour wipe
    Serial.println("SnowflakeNonBlock finished");

    // reset pixNum so other functions start from 0; only if needed
     pixNum = 0;
      }
      
      break;

      case BlueSnowflake: if(Snowflakes(strip.Color(0, 0, 255), 40) == false)
      {
  
    // done with colour wipe
    Serial.println("SnowflakeNonBlock finished");

    // reset pixNum so other functions start from 0; only if needed
     pixNum = 0;
      }
      
      break;

      case GreenSnowflake: if(Snowflakes(strip.Color(0, 255, 0), 40) == false)
      {
  
    // done with colour wipe
    Serial.println("SnowflakeNonBlock finished");

    // reset pixNum so other functions start from 0; only if needed
     pixNum = 0;
      }
      
      break;

      case PurpleSnowflake: if(Snowflakes(strip.Color(75, 0, 130), 40) == false)
      {
  
    // done with colour wipe
    Serial.println("SnowflakeNonBlock finished");

    // reset pixNum so other functions start from 0; only if needed
     pixNum = 0;
      }
      
      break;
      
    // other cases here
    

  }
}

bool Snowflakes(uint32_t c, uint8_t wait)
{
  
  
  // variables that will be remembered between successive calls
  // start time for delay
  static unsigned long startTime;
  // indication if Rainbow is in progress
  static bool inProgress = false;

  // if Rainbow is not yet in progress
  if (inProgress == false)
  {
    // indicate that it's in progress
    inProgress = true;
    // set the start time (for delay)
    startTime = millis();
  }

  // if a 'delay' period has lapsed
  if (millis() - startTime >= wait)
  {
    // Setup the pixel array
    int pixel[PIXEL_COUNT];
    for(int p=0; p<PIXEL_COUNT; p++){
    pixel[p] = random(0,255); 
    }

    // Run some snowflake cycles
    for (int j=0; j<200; j++) {

    // Every five cycles, light a new pixel
    if((j%5)==0){
    strip.setPixelColor(random(0,60), c);
    }

    // Dim all pixels by 10
   for(int p=0; p<PIXEL_COUNT; p++){
   strip.setPixelColor(p, pixel[p],pixel[p],pixel[p] );
   pixel[p] =  pixel[p] - 10;
   }
   
    
    strip.show();
   
    delay(wait);
    }
      
  
    // 'reset' the start time for the delay
    startTime = millis();
    // next time that 'delay' has lapsed, use next pixel
    pixNum++;
  }

  // if all pixels done
  if(pixNum == strip.numPixels())
  {
    // color wipe finished
    inProgress = false;
  }

  // indicate the status to caller
  return inProgress;
  }

johnwasser:

      pixel[p] = random(0, 255);

You initialize each pixel to a value from 0 to 254.

     // Dim all pixels by 10

for (int p = 0; p < PIXEL_COUNT; p++)
     {
       strip.setPixelColor(p, pixel[p], pixel[p], pixel[p] );
       pixel[p] =  pixel[p] - 10;
     }



You use the same value for Red, Green, and Blue so that explains why your pixels are all white. If you want different colors, you could make 'pixel' an array of colors instead of an array of integers. Initialize the Red Green and Blue parts of each pixel to different values. Dim the three parts of the pixel separately.

So should i be creating a pixel1 [p], pixel2 [p] and pixel3 [p] for red green and blue? Could you provide an example?

rexshow:
So should i be creating a pixel1 [p], pixel2 [p] and pixel3 [p] for red green and blue? Could you provide an example?

Why call them 'pixel1', 'pixel2', and 'pixel3' when they represent Red, Blue, and Green? I would go with a 2-dimensional array:

    // Setup the pixel array
    byte pixel[3][PIXEL_COUNT];
    for (int p = 0; p < PIXEL_COUNT; p++)
    {
      pixel[0][p] = random(256);
      pixel[1][p] = random(256);
      pixel[2][p] = random(256);
    }
      // Dim all pixels by 10
      for (int p = 0; p < PIXEL_COUNT; p++)
      {
        strip.setPixelColor(p, pixel[0][p], pixel[1][p], pixel[2][p] );
        pixel[0][p] -= 10;
        pixel[1][p] -= 10;

        pixel[2][p] -= 10;
      }

johnwasser:
Why call them 'pixel1', 'pixel2', and 'pixel3' when they represent Red, Blue, and Green? I would go with a 2-dimensional array:

    // Setup the pixel array

byte pixel[3][PIXEL_COUNT];
    for (int p = 0; p < PIXEL_COUNT; p++)
    {
      pixel[0][p] = random(256);
      pixel[1][p] = random(256);
      pixel[2][p] = random(256);
    }





// Dim all pixels by 10
      for (int p = 0; p < PIXEL_COUNT; p++)
      {
        strip.setPixelColor(p, pixel[0][p], pixel[1][p], pixel[2][p] );
        pixel[0][p] -= 10;
        pixel[1][p] -= 10;

pixel[2][p] -= 10;
      }

I tried the above code but instead of it being white like it was before, the LED's now will all light a different random color, if i set pixel0 to 255 and the rest to 0 then it will do a red flash but still have random colors mixed in instead of being just red, any ideas?

rexshow:
I tried the above code but instead of it being white like it was before, the LED's now will all light a different random color, if i set pixel0 to 255 and the rest to 0 then it will do a red flash but still have random colors mixed in instead of being just red, any ideas?

I thought the whole point was to get colors other than white. I guess I misunderstood your requirements. Perhaps you can modify the code to do what you want, now that you can assign any color to any pixel.

johnwasser:
I thought the whole point was to get colors other than white. I guess I misunderstood your requirements. Perhaps you can modify the code to do what you want, now that you can assign any color to any pixel.

Even if i just want the color say red for example and set it like shown below, it will still show random colors in between the main color of red and will also not perform the effect properly with the red color either, any ideas what that might be or is the code not designed for it?

// Setup the pixel array
byte pixel[3][PIXEL_COUNT];
for (int p = 0; p < PIXEL_COUNT; p++)
{
pixel[0][p] = random(256);
pixel[1][p] = random(0);
pixel[2][p] = random(0);
}

rexshow:
any ideas what that might be or is the code not designed for it?

When you 'fade out' by repeatedly subtracting 10 you are likely to get negative numbers. Try this to avoid that:

        pixel[0][p] = max(pixel[0][p] - 10, 0);
        pixel[1][p] = max(pixel[1][p] - 10, 0);
        pixel[2][p] = max(pixel[2][p] - 10, 0);