Random specific colors for NeoPixel

Hello everyone! I apologize, I am a noob when it comes to programming Neopixels. I don't know where I should start, I am looking to try to:

  1. Have LEDs 1-5 be their own color and 6-10 be their own color. So half is one color, half is another, or could be both sets, at random

  2. Pulse or breathing effect in the lights

  3. I want to try and have the pro trinket choose from 5 different colors for the LED sets to change to after a timer or delay

I am still new to this so any advice would be greatly appreciated! Thanks

Put the colour codes that you want in an array and use the random() function to select the index to the array

Do you have a Arduino board ? The Pro Trinket has no advantages, only disadvantages.

Thanks! I was trying to wrap my head around doing that, I was thinking....and correct me if this won't work, I was going to use int to make 5 integers for each color and then try and use random to switch between each defined int. The other part is trying to make 1-5 a random color and 6-10 a different color.

I do not have an arduino board, I was using a tutorial online that used a pro trinket for cosplay props, so I bought that for the small size so I can hide it inside somewhere.

So I have this so far, but don't know where to continue from here. Don't know how/where to add the random function into this void loop.

void loop() {

colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
colorWipe(strip.Color(255, 255, 0), 50); // yellow
colorWipe(strip.Color(128, 0, 128), 50); //purple


@cyborgkangaroo, your topic has been moved to a more suitable location. Introductory Tutorials is not for questions but for tutorials that e.g. you write. Feel free to write one once you have mastered your problem :wink:

Can you please spend some time reading How to get the best out of this forum and in future use code tags when posting code. We would also prefer it if you post full code so (in this case) we know which library you're using.

Do you know how to control an individual led in the strip? Have a look at e.g. the blink example that comes with the FastLed library. The below is a modified example for a strip with 10 leds.

#include <FastLED.h>

// How many leds in your strip?
#define NUM_LEDS 10

// For led chips like Neopixels, which have a data line, ground, and power, you just
// need to define DATA_PIN.  For led chipsets that are SPI based (four wires - data, clock,
// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 3
#define CLOCK_PIN 13

// Define the array of leds

void setup() {
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

void loop()
  // set the colours
  for (int cnt = 0; cnt < 5; cnt++)
    leds[cnt] = CRGB::Red;
  for (int cnt = 5; cnt < 10; cnt++)
    leds[cnt] = CRGB::Blue;
  // and show

  // clear the strip
  for (int cnt = 0; cnt < 10; cnt++)
    leds[cnt] = CRGB::Black;

// edit
Fixed code

1 Like

My apologies, did not know I was in the wrong section, I have used the blink example for the on board light, I will give this one a try, thank you so much.

There were some mistakes in the code that I posted. I've fixed them.

The updated sketch from sterretje from reply #7:

In the middle-upper of the screen is a start button. Click on it, that's all.

Can you please spend some time reading How to get the best out of this forum and in use code tags when posting code. It's described in the link.

1 Like

Ok, I looked at the guide for the code tags, sorry about that. Did not realize the code tags made things easier to read on the forum haha I did use the tag in the beginning and also auto formatted the code before pasting.

This is what I got so far, I have the lights cycling through blue,fading in and then out and repeating, but don't know how to make multiple rainbowCycles with the different colors and then having a random function choose 1 of the 5 colors to cycle through and then loop the random function again after a delay.

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>

#define PIN 6

Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  // This is for Trinket 5V 16MHz,
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);

  strip.show(); // Initialize all pixels to 'off'

void loop() {



void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for (j = 0; j < 256 * 5; j++) { // 5 cycles of all colors on wheel
    for (i = 0; i < strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));

// Currently setup to slowly fade the blue LEDs down the strip
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(0, 0, WheelPos * 3);
  if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, 0, 255 - WheelPos * 3);
  WheelPos -= 170;
  return strip.Color(0, 0, 0);


And liked them so much that you used them twice :grinning:

I installed the blink and just extended the code to do all the colors! This was the answer to my problem! Thank you so much!

If your problem is solved, please tick the solution checkbox under the most useful reply; that way others that have a similar problem can know that a solution was provided / the problem was solved.