Simple glimmer-style NeoPixel sketch

Hey everyone!

Like many I'm relatively new to the Arduino world, but I have familiarized myself with some of the basics and getting my NeoPixels working with the strip test program and a few others. My current project is pretty simple. I'm looking to have a strip of 14 LEDs turn on, 5 in blue, and 9 in orange and I'd like them to always be on, but every so often have a random LED slightly dim for half a second or so, then go back to its original brightness. I envision it kinda like a basic glimmer effect.

Is there a sketch already made that is similar to this that I could modify or is there a better way to do it?

Thank you!

It's hard to say. I can't see Your sketch and compare. Attach Your sketch, using "code tags"! That sketch You know and it would be the best to develope it further.

Find a random-twinkle sketch and change it to dim instead of brighten.

It’s hard to say. I can’t see Your sketch and compare.
Attach Your sketch, using “code tags”! That sketch You know and it would be the best to develope it further.

Unfortunately I don’t have a sketch yet, all I have is a random one I found where I modified it to let me pick what position and what color I want each LED to be. I’m not sure if its even remotely close to what I should be using, all I know is it works so far, just without that glimmer effect I was looking for.

Thanks for the response!

#define WS2812_pin 8 // only digital pin 8 works right now
#define numberOfLEDs 45// total number of RGB LEDs
byte RGB[135];//take your number of LEDs and multiply by 3

void RGB_update(int LED, byte RED, byte GREEN, byte BLUE);//function to drive LEDs

void setup() {
  pinMode(WS2812_pin, OUTPUT);

void loop() {

RGB_update(0,3,48,252);//LED#, RED, GREEN, BLUE
RGB_update(1,3,48,252);//LED#, RED, GREEN, BLUE
RGB_update(2,3,48,252);//LED#, RED, GREEN, BLUE
RGB_update(3,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(4,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(5,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(6,3,48,252);//LED#, RED, GREEN, BLUE
RGB_update(7,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(8,3,48,252);//LED#, RED, GREEN, BLUE
RGB_update(9,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(10,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(11,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(12,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(13,252,55,3);//LED#, RED, GREEN, BLUE
RGB_update(14,252,55,3);//LED#, RED, GREEN, BLUE


//WS2812 Driver Function
void RGB_update(int LED, byte RED, byte GREEN, byte BLUE) {
  // LED is the LED number starting with 0
  // RED, GREEN, BLUE is the brightness 0..255 setpoint for that LED
  byte ExistingPort, WS2812pinHIGH;//local variables here to speed up pinWrites
  if(LED>=0){//map the REG GREEN BLUE Values into the RGB[] array
  RGB[LED * 3] = GREEN;
  RGB[LED * 3 + 1] = RED;
  RGB[LED * 3 + 2] = BLUE;
  noInterrupts();//kill the interrupts while we send the bit stream out...
  ExistingPort = PORTB; // save the status of the entire PORT B - let's us write to the entire port without messing up the other pins on that port
  WS2812pinHIGH = PORTB | 1; //this gives us a byte we can use to set the whole PORTB with the WS2812 pin HIGH
  int bitStream = numberOfLEDs * 3;//total bytes in the LED string

//This for loop runs through all of the bits (8 at a time) to set the WS2812 pin ON/OFF times
  for (int i = 0; i < bitStream; i++) {

    PORTB = WS2812pinHIGH;//bit 7  first, set the pin HIGH - it always goes high regardless of a 0/1 
    //here's the tricky part, check if the bit in the byte is high/low then right that status to the pin
    // (RGB[i] & B10000000) will strip away the other bits in RGB[i], so here we'll be left with B10000000 or B00000000
    // then it's easy to check if the bit is high or low by AND'ing that with the bit mask ""&& B10000000)"" this gives 1 or 0
    // if it's a 1, we'll OR that with the Existing port, thus keeping the pin HIGH, if 0 the pin is written LOW
    PORTB = ((RGB[i] & B10000000) && B10000000) | ExistingPort; 
    __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");//these are NOPS - these let us delay clock cycles for more precise timing 
    PORTB = ExistingPort;//okay, here we know we have to be LOW regardless of the 0/1 bit state
    __asm__("nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t""nop\n\t");//minimum LOW time for pin regardless of 0/1 bit state

    // then do it again for the next bit and so on... see the last bit though for a slight change

    PORTB = WS2812pinHIGH;//bit 6
    PORTB = ((RGB[i] & B01000000) && B01000000) | ExistingPort;
    PORTB = ExistingPort;

    PORTB = WS2812pinHIGH;//bit 5
    PORTB = ((RGB[i] & B00100000) && B00100000) | ExistingPort;
    PORTB = ExistingPort;

    PORTB = WS2812pinHIGH;//bit 4
    PORTB = ((RGB[i] & B00010000) && B00010000) | ExistingPort;
    PORTB = ExistingPort;

    PORTB = WS2812pinHIGH;//bit 3
    PORTB = ((RGB[i] & B00001000) && B00001000) | ExistingPort;
    PORTB = ExistingPort;

    PORTB = WS2812pinHIGH;//bit 2
    PORTB = ((RGB[i] & B00000100) && B00000100) | ExistingPort;
    PORTB = ExistingPort;

    PORTB = WS2812pinHIGH;//bit 1
    PORTB = ((RGB[i] & B00000010) && B00000010) | ExistingPort;
    PORTB = ExistingPort;

    PORTB = WS2812pinHIGH;//bit 0
    __asm__("nop\n\t");//on this last bit, the check is much faster, so had to add a NOP here
    PORTB = ((RGB[i] & B00000001) && B00000001) | ExistingPort;
    PORTB = ExistingPort;//note there are no NOPs after writing the pin LOW, this is because the FOR Loop uses clock cycles that we can use instead of the NOPS
  }//for loop

  interrupts();//enable the interrupts

// all done!
}//void RGB_update

You could get there from here. But I suggest you upgrade to the FastLED library. It has a lot more functions for working with LED strings of many different types.

Work through the FastLED examples. Note that most of them are simple demos like you already have, using delay() to create animations. If you attempt to do anything else with your Arduino, you will have to re-write the animations without delay(). There's a good tutorial over at Adafruit on how to do that.